请问什么情况factory.owners会有多个元素?
来源:3-11 异步组件(工厂函数)

BT7274
2021-04-25
请问什么情况factory.owners会有多个元素?
factory.owners的每一项都是currentRenderingInstance,是在调用组件的render函数之前设置为组件实例的。
什么样的写法或者加载流程才会让owners有多个组件实例?
写回答
2回答
-
多个组件都注册了这个异步组件,就会有多个 owners,或者同一个组件有多个实例,也会有这种情况。
022021-04-26 -
BT7274
提问者
2021-04-26
// 总结了一下一个异步组件被多个组件引用并render后factory.owners有多个vm的情况 const HelloWorld = function () { return new Promise(resolve => { window.setTimeout(() => { resolve({ name: 'HelloWorld', render(h) { return h('button', 'I am <HelloWorld />') } }) }, 3000) }) } const TestOwners1 = { name: 'TestOwners1', render(h) { return h(HelloWorld) } } const TestOwners2 = { name: 'TestOwners2', render(h) { return h(HelloWorld) } } const app = new Vue({ el: '#app', render: h => h('div', [h(HelloWorld), h(TestOwners1), h(TestOwners2)]) }) const app1 = new Vue({ el: '#app1', render: h => h('div', [h(HelloWorld)]) })
00
相似问题