1 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超7個(gè)贊
您所需要做的就是將模板作為字符串模板從 DOM 移動(dòng)到主組件中。只要<div id="live-blogs"></div>頁面上有某個(gè)地方,它就可以工作。
Vue.component('live-blog', {
props: ['id', 'title'],
template: '<div class="lb-entry">{{ title }}</div>',
});
new Vue({
el: '#live-blogs',
template: `
<div>
<live-blog
v-for="blog in blogs"
:key="blog.id"
:title="blog.title"
/>
</div>`,
data() {
return {
blogs: [],
};
},
methods: {
getLiveBlogs() {
request.get('/read/' + id)
.then(response => {
this.blogs = response.data.data;
});
},
},
mounted() {
this.getLiveBlogs();
},
});
- 1 回答
- 0 關(guān)注
- 127 瀏覽
添加回答
舉報(bào)