我有以下代码,我正在使用两个组件,一个称为Mustaches,另一个称为Mustache
我正在尝试使用Mustaches中的Mustache显示数据v-for
我没有收到任何数据或任何错误,Mustaches html 显示在源代码中,但未显示Mustache数据。
HTML
<div id="app">
<moustaches>
<moustache name="The Burgundy" img="/img/the-burgundy.jpg"></moustache>
<moustache name="The Borat" img="/img/the-borat.jpg"></moustache>
<moustache name="The Santana" img="/img/the-santana.jpg"></moustache>
</moustaches>
</div>
JS
Vue.component('moustaches', {
template: `
<div>
<ul class="list-inline">
<li v-for="moustache in moustaches">
<p>
<strong>@{{ moustache.name }}</strong>
</p>
<img width="300" height="200" :src="moustache.img">
<button
class="btn btn-primary"
:data-type="moustache.name"
>
Vote
</button>
</li>
</ul>
</div>
`,
mounted() {
console.log(this.$children);
},
data() {
return { moustaches: [] };
},
created() {
this.moustaches = this.$children;
}
});
Vue.component('moustache', {
template: `
<div><slot></slot></div>
`,
props: {
name: { required: true },
img: { required: true},
selected: { default: false }
}
});
new Vue({
el: '#app'
});
呈现的 HTML
<div><ul class="list-inline"></ul></div>