我正在学习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(在 组件中找到)
谁能告诉我为什么?谢谢!
? – Soviut