【发布时间】:2020-10-21 12:29:39
【问题描述】:
Vue 3 文档中的这段代码,它正在运行。
const data = { a: 1 }
// The object is added to a component instance
const vm = Vue.createApp({
data() {
return data
}
}).mount('#app')
console.log(vm.a) // => 1
但是,如果我使用render() 函数创建组件,我无法访问数据对象。
let options = window[this.data.get('index')];
options.baseUrl = window['baseUrl'];
const app2 = Vue.createApp({
render() {
const {h} = Vue;
return h(app.component('ComponentA'), options)
}
})
.mount("#app");
console.log(app2.baseUrl); // undefined
console.log(app2.$data); // {}
【问题讨论】:
标签: javascript vue.js vuejs3