【发布时间】:2020-07-11 01:47:11
【问题描述】:
所以我有这个设置,它在表组件的 v-for 构造上崩溃。它显示一个错误:“属性或方法“tablesList”未在实例上定义,但在渲染期间被引用”。如果我省略 v-for table-component 渲染。如果我从“容器”组件访问这些数据,一切都很好。所以问题在于从父模板中的子模板访问数据。
我做错了什么?
let container = Vue.component("container", {
props: ["item"],
template: `<div class="container">
<table-component v-for="item in tablesList"></table-component>
</div>`
});
let table = Vue.component("table-component", {
props: ["item"],
template: `<div class="table">
this is a table
</div>`
});
let app = new Vue({
el: "#app",
data() {
return {
containersList: [],
tablesList: [{item:'item'}]
};
},
methods: {
anyMethod() {
}
}
});
</script>
【问题讨论】:
-
为什么不将
tablesList添加到container组件而不是table-component? -
tablesList 在 Vue 实例中而不是在表组件中。还是我误会了?
标签: javascript vue.js