[英]How to use/import data in App.vue from constructor
I'm initializing my app with main.js
like so,我像这样用
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),
});
I'm trying to make use of items
within App.vue
.我正在尝试使用
App.vue
中的items
。 But I'm not sure how or if it's passed down into it.但我不确定它是如何或是否传递给它的。
App.vue looks like so... App.vue 看起来像这样......
export default {
props['items'], // not sure if that's correct
created() {
console.log(this.items); // always returns undefined
}
}
So how do I get data from the constructor and make use of it?那么如何从构造函数中获取数据并加以利用呢? Thank you for your help!
谢谢您的帮助!
In order to pass props
via the render
function, you need to provide a context
object.为了通过
render
函数传递props
,您需要提供一个context
对象。 See https://v2.vuejs.org/v2/guide/render-function.html#createElement-Arguments见https://v2.vuejs.org/v2/guide/render-function.html#createElement-Arguments
render: h => h(App, {
props: {
items: store.items
}
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.