admin管理员组文章数量:1335624
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!
Share Improve this question edited Jan 13, 2017 at 6:02 K Scandrett 16.5k4 gold badges42 silver badges68 bronze badges asked Jan 13, 2017 at 5:09 JohnhorseJohnhorse 231 gold badge1 silver badge4 bronze badges 1- Are you using pug/jade templates in your ponents? – Soviut Commented Jan 13, 2017 at 6:05
2 Answers
Reset to default 3You 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>',
本文标签: javascriptVue warn Failed to resolve directive refStack Overflow
版权声明:本文标题:javascript - [Vue warn]: Failed to resolve directive: ref - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742374137a2462818.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论