提交 7fa14714 编写于 作者: fxy060608's avatar fxy060608

fix(app): $ownerInstance

上级 777bd4e6
import { createApp, ComponentOptions, ComponentPublicInstance } from 'vue' import { createApp, ComponentOptions, ComponentPublicInstance } from 'vue'
import { formatLog, RENDERJS_MODULES } from '@dcloudio/uni-shared' import { formatLog, RENDERJS_MODULES } from '@dcloudio/uni-shared'
import {
createComponentDescriptorVm,
getComponentDescriptor,
} from '@dcloudio/uni-core'
import { UniNode } from './elements/UniNode' import { UniNode } from './elements/UniNode'
import { UniCustomElement } from './components' import { UniCustomElement } from './components'
...@@ -27,7 +31,7 @@ function initRenderjsModule(node: UniNode, moduleId: string) { ...@@ -27,7 +31,7 @@ function initRenderjsModule(node: UniNode, moduleId: string) {
} }
const el = node.$ as UniCustomElement const el = node.$ as UniCustomElement
;(el.__renderjsInstances || (el.__renderjsInstances = {}))[moduleId] = ;(el.__renderjsInstances || (el.__renderjsInstances = {}))[moduleId] =
createRenderjsInstance(options) createRenderjsInstance(el, options)
} }
function getRenderjsModule(moduleId: string) { function getRenderjsModule(moduleId: string) {
...@@ -41,9 +45,19 @@ function getRenderjsModule(moduleId: string) { ...@@ -41,9 +45,19 @@ function getRenderjsModule(moduleId: string) {
} }
function createRenderjsInstance( function createRenderjsInstance(
el: UniCustomElement,
options: ComponentOptions options: ComponentOptions
): ComponentPublicInstance { ): ComponentPublicInstance {
options = options.default || options options = options.default || options
options.render = () => {} options.render = () => {}
return createApp(options).mount(document.createElement('div')) return createApp(options)
.mixin({
mounted() {
this.$ownerInstance = getComponentDescriptor(
createComponentDescriptorVm(el),
false
)
},
})
.mount(document.createElement('div'))
} }
...@@ -221,11 +221,10 @@ function createComponentDescriptor( ...@@ -221,11 +221,10 @@ function createComponentDescriptor(
vm: ComponentDescriptorVm, vm: ComponentDescriptorVm,
isOwnerInstance = true isOwnerInstance = true
) { ) {
if (isOwnerInstance && vm) { if (__PLATFORM__ === 'h5') {
if (__PLATFORM__ === 'h5') { if (isOwnerInstance && vm) {
vm = resolveOwnerVm((vm as ComponentPublicInstance).$)! vm = resolveOwnerVm((vm as ComponentPublicInstance).$)!
} }
// TODO App
} }
if (vm && vm.$el) { if (vm && vm.$el) {
if (!vm.$el.__wxsComponentDescriptor) { if (!vm.$el.__wxsComponentDescriptor) {
......
...@@ -1199,8 +1199,8 @@ class ComponentDescriptor { ...@@ -1199,8 +1199,8 @@ class ComponentDescriptor {
} }
} }
function createComponentDescriptor(vm, isOwnerInstance = true) { function createComponentDescriptor(vm, isOwnerInstance = true) {
if (isOwnerInstance && vm) { {
{ if (isOwnerInstance && vm) {
vm = resolveOwnerVm(vm.$); vm = resolveOwnerVm(vm.$);
} }
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册