我正在使用 main.js
初始化我的应用程序,如下所示,
import App from './App.vue';
const store = {
items: [{
todo: 'Clean Apartment.',
},{
todo: 'Mow the lawn!',
},{
todo: 'Pick up eggs, milk & flour',
}, {
todo: 'Watch the big game',
}],
};
const app = new Vue({
el: '#app-zone',
data: store, // is this not sending the store data into App.vue?
render: h => h(App),
});
我正在尝试在 App.vue
中使用 items
。但我不确定它是如何或是否被传递到其中的。
App.vue 看起来像这样...
export default {
props['items'], // not sure if that's correct
created() {
console.log(this.items); // always returns undefined
}
}
那么如何从构造函数获取数据并使用它呢?感谢您的帮助!
最佳答案
为了通过 render
函数传递 props
,您需要提供一个 context
对象。请参阅https://v2.vuejs.org/v2/guide/render-function.html#createElement-Arguments
render: h => h(App, {
props: {
items: store.items
}
})
关于javascript - 如何从构造函数中使用/导入 App.vue 中的数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42355928/