admin管理员组文章数量:1399788
I'm just starting with Vue and I have defined 2 ponents, however, I cannot render them in the same 'Vue' instance.
Here are my 2 ponents:
Vueponent('mat-example', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
Vueponent('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
Next, I do have the 'Vue' entry point defined:
var app = new Vue({
el: '#app'
});
And in my HTML, I do have the following code:
<div id="app">
<button-counter />
<mat-example />
</div>
The 'Vue' development tools does only show the 'button-counter' ponent:
If I remove the 'button-counter', the 'mat-example' is showed up in the Vue Developer Tools.
How does it e that I cannot render those 2 ponents in my Vue entry point?
I'm just starting with Vue and I have defined 2 ponents, however, I cannot render them in the same 'Vue' instance.
Here are my 2 ponents:
Vue.ponent('mat-example', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
Vue.ponent('button-counter', {
data: function () {
return {
count: 0
}
},
template: '<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
Next, I do have the 'Vue' entry point defined:
var app = new Vue({
el: '#app'
});
And in my HTML, I do have the following code:
<div id="app">
<button-counter />
<mat-example />
</div>
The 'Vue' development tools does only show the 'button-counter' ponent:
If I remove the 'button-counter', the 'mat-example' is showed up in the Vue Developer Tools.
How does it e that I cannot render those 2 ponents in my Vue entry point?
Share Improve this question asked Apr 14, 2018 at 7:55 ComplexityComplexity 5,8306 gold badges46 silver badges90 bronze badges 1-
What is the root ponent for
Vue
? – fitzberg Commented Aug 11, 2022 at 16:31
2 Answers
Reset to default 8this is going to work:
<div id="app">
<button-counter></button-counter>
<mat-example></mat-example>
</div>
demo:
Vue.ponent('mat-example', {
data: function() {
return {
count: 0
}
},
template:
'<button v-on:click="count++">You clicked me {{ count }} times.</button>'
})
Vue.ponent('button-counter', {
data: function() {
return {
count: 0
}
},
template:
'<button v-on:click="count++">You clicked me {{ count }} times</button>'
})
var app = new Vue({
el: '#app'
})
<script src="https://cdn.jsdelivr/npm/[email protected]/dist/vue.js"></script>
<div id="app">
<button-counter></button-counter>
<mat-example></mat-example>
</div>
Use this tag instead of using self closing tag
<div id="app">
<button-counter></button-counter>
<mat-example></mat-example>
</div>
本文标签: javascriptCannot render multiple components in VueStack Overflow
版权声明:本文标题:javascript - Cannot render multiple components in Vue - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744226769a2596128.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论