I'm learning about Components in Vue.js.
The template is:
<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>
and the JS is:
Vueponent('parent', {
template: '#parent',
methods: {
getChildren:function() {
alert(this.$refs1);
alert(this.$refs2);
}
},
ponents: {
'child1': {
template: '#child1',
data: function() {
return {
msg: 'This is the child1 ~!'
}
}
},
'child2': {
template: '#child2',
data: function() {
return {
msg: 'This is the child2 ~!'
}
}
}
}
});
Vue throws
warn:vue.js:525 [Vue warn]: Failed to resolve directive: ref (found in ponent )
Who can tell me why? Thanks!
I'm learning about Components in Vue.js.
The template is:
<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>
and the JS is:
Vue.ponent('parent', {
template: '#parent',
methods: {
getChildren:function() {
alert(this.$refs1);
alert(this.$refs2);
}
},
ponents: {
'child1': {
template: '#child1',
data: function() {
return {
msg: 'This is the child1 ~!'
}
}
},
'child2': {
template: '#child2',
data: function() {
return {
msg: 'This is the child2 ~!'
}
}
}
}
});
Vue throws
warn:vue.js:525 [Vue warn]: Failed to resolve directive: ref (found in ponent )
Who can tell me why? Thanks!
You are using Vue 2.0 with Vue 1.0 grammar:
see the migration documentation:
https://v2.vuejs/v2/guide/migration.html#v-el-and-v-ref-replaced
So, you should use:
<child1 ref="cc1"></child1>
<child2 ref="cc2"></child2>
Or change the Vue version back to 1.x
Unless you are using Pug (formerly Jade) in your ponent templates, you need to use HTML:
template: '<div id="parent"></div>',