提交 83ba4635 编写于 作者: fxy060608's avatar fxy060608

fix(app): wxs event (#3324)

上级 ef2890c5
......@@ -96,7 +96,8 @@ export class UniComponent extends UniNode {
;(this.$holder || this.$).textContent = text
}
addWxsEvent(name: string, wxsEvent: string, flag: number) {
this.$props[name] = createWxsEventInvoker(this.$, wxsEvent, flag)
// 此时 $ 还不存在,故传入 this,等事件触发时,再获取 $
this.$props[name] = createWxsEventInvoker(this, wxsEvent, flag)
}
addEvent(name: string, value: number) {
this.$props[name] = createInvoker(this.id, value, parseEventName(name)[1])
......
......@@ -10,6 +10,8 @@ import {
import { VD_SYNC } from '../../../../constants'
import { UniCustomElement } from '../components'
import { invokeWxsEvent } from '../wxs'
import type { UniComponent } from '../components/UniComponent'
import { isUniComponent } from '../utils'
function removeEventListener(el: UniCustomElement, type: string) {
const listener = el.__listeners[type]
......@@ -108,13 +110,13 @@ export function patchWxsEvent(
}
export function createWxsEventInvoker(
el: UniCustomElement,
el: UniCustomElement | UniComponent,
wxsEvent: string,
flag: number
) {
const invoker = (evt: Event) => {
invokeWxsEvent(
el,
isUniComponent(el) ? el.$ : el,
wxsEvent,
normalizeNativeEvent(evt)[0] as Record<string, any>
)
......
import { JSON_PROTOCOL, WXS_PROTOCOL } from '@dcloudio/uni-shared'
import { isString } from '@vue/shared'
import { UniCustomElement } from './components'
import type { UniCustomElement } from './components'
import type { UniComponent } from './components/UniComponent'
import { invokeWxs } from './wxs'
const JSON_PROTOCOL_LEN = JSON_PROTOCOL.length
......@@ -20,3 +21,10 @@ export function decodeAttr(el: UniCustomElement, value: unknown) {
export function isCssVar(name: string) {
return name.indexOf('--') === 0
}
export function isUniComponent(
el: UniCustomElement | UniComponent
): el is UniComponent {
// 不使用 instanceof 判断,因为需要引入 UniComponent,两者循环依赖
return !!(el as UniComponent).addWxsEvent
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册