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

fix(wxs): ownerInstance

上级 050515c8
......@@ -48,15 +48,18 @@ export default {
return $event
}
Vue.prototype.$getComponentDescriptor = function (vm) {
return createComponentDescriptor(vm || this)
Vue.prototype.$getComponentDescriptor = function (vm, owner = false) {
return createComponentDescriptor(vm || this, owner)
}
Vue.prototype.$handleWxsEvent = function ($event) {
if ($event instanceof Event) { // 未处理的 event 对象 需要对 target 校正及包装
const currentTarget = $event.currentTarget
const instance = currentTarget && currentTarget.__vue__ && currentTarget.__vue__.$getComponentDescriptor()
$event = processEvent.call(this, $event.type, $event, {}, findUniTarget($event, this.$el) || $event.target, $event.currentTarget)
const instance = currentTarget &&
currentTarget.__vue__ &&
currentTarget.__vue__.$getComponentDescriptor(null, true)
$event = processEvent.call(this, $event.type, $event, {}, findUniTarget($event, this.$el) || $event.target,
$event.currentTarget)
$event.instance = instance
}
return $event
......
......@@ -108,7 +108,7 @@ class ComponentDescriptor {
const clsIndex = addWxsClsArr.findIndex(oldCls => oldCls === cls)
if (clsIndex !== -1) { // 在 addWxsClass 中
addWxsClsArr.splice(clsIndex, 1)
}
}
removeWxsClsArr.push(cls)
})
this.$el.__wxsRemoveClass = removeWxsClsArr
......@@ -146,11 +146,12 @@ class ComponentDescriptor {
}
}
export function createComponentDescriptor (vm) {
export function createComponentDescriptor (vm, owner = false) {
if (vm && vm.$el) {
if (!vm.$el.__wxsComponentDescriptor) {
vm.$el.__wxsComponentDescriptor = new ComponentDescriptor(vm)
const key = owner ? '__wxsComponentDescriptorOwner' : '__wxsComponentDescriptor'
if (!vm.$el[key]) {
vm.$el[key] = new ComponentDescriptor(vm)
}
return vm.$el.__wxsComponentDescriptor
return vm.$el[key]
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册