2017-01-13 59 views
1

我正在学习Vue.js中的组件。[Vue warn]:无法解析指令:ref

模板是:

<script type="text/template" id="child1"> 
    <h3>This is the child1~!</h3> 
</script> 
<script type="text/template" id="child2"> 
    <h3>This is the child2~!</h3> 
</script> 
<script id="parent" type="text/template"> 
    <div> 
     <h2>This is the parent~!</h2> 
     <child1 v-ref:cc1></child1> 
     <child2 v-ref:cc2></child2> 
     <button v-on:click="getChildren">get children msg</button> 
    </div> 
</script> 

和JS是:

Vue.component('parent', { 
     template: '#parent', 
     methods: { 
      getChildren:function() { 
       alert(this.$refs.cc1); 
       alert(this.$refs.cc2); 
      } 
     }, 
     components: { 
      'child1': { 
       template: '#child1', 
       data: function() { 
        return { 
         msg: 'This is the child1 ~!' 
        } 
       } 
      }, 
      'child2': { 
       template: '#child2', 
       data: function() { 
        return { 
         msg: 'This is the child2 ~!' 
        } 
       } 
      } 
     } 
    }); 

Vue公司抛出

警告:vue.js:525 Vue公司警告]:无法解析指令:ref(在 组件中找到)

谁能告诉我为什么?谢谢!

+0

? – Soviut

回答

0

除非你是在你的组件模板中使用帕格(原玉),你需要使用HTML:

template: '<div id="parent"></div>', 
相关问题