【发布时间】:2017-06-19 19:19:04
【问题描述】:
渲染模板有点问题。似乎来自主实例的数据没有传输到组件。
这是 Vue 代码:
Vue.component('country-list', {
template: `
<tr class=parent>
<country v-for="country in countryList">
<td>Render This</td>
</country>
</tr>
`,
props: ['countries'],
data() {
return {
countryList: this.countries
}
}
});
Vue.component('country', {
template: `<tbody class=parent><slot></slot></tbody>`
});
let App = new Vue({
el: '#app-container',
data: {
countries: []
},
created() {
this.getCountries()
},
methods: {
getCountries() {
var self = this;
axios.get('/admin/countries')
.then(function (response) {
self.countries = response.data.data;
})
.catch(function (error) {
console.log(error);
});
},
filterCountries() {
},
updateCountry(event) {
}
}
})
以及使用 country-list 模板的 HTML 代码:
<table class="table table-striped table-hover">
<thead>
<tr>
<td>
<input
type="text"
id="country-filter"
@keyup="filterCountries">
</td>
</tr>
<tr>
<td>Country Name</td>
<td>Visible</td>
<td>Order</td>
<td>Actions</td>
</tr>
</thead>
<tbody>
<country-list></country-list>
</tbody>
</table>
我在这里做错了什么?
【问题讨论】:
-
您正试图将
tbody作为tr的直接子代。你不能那样做。
标签: vue.js vuejs2 vue-component