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

wip(mp): event

上级 a4398787
......@@ -6,7 +6,7 @@ describe('compiler: transform v-model', () => {
`<Comp v-model="model" />`,
`<comp class="vue-ref" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event.detail.__args__[0]) }
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
}`
)
})
......@@ -15,7 +15,7 @@ describe('compiler: transform v-model', () => {
`<Comp v-model="model" />`,
`<comp class="vue-ref" modelValue="{{a}}" bindupdateModelValue="{{b}}"/>`,
`(_ctx, _cache) => {
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event.detail.__args__[0]) }
return { a: _ctx.model, b: _vOn($event => _ctx.model = $event) }
}`,
{
cacheHandlers: true,
......
......@@ -125,7 +125,7 @@ function transformComponentVModel(
): DirectiveNode[] {
return transformVModel(props, context, {
formatEventCode(code) {
return code.replace(`= $event`, `= $event.detail.__args__[0]`)
return code
},
})
}
......
......@@ -5014,7 +5014,11 @@ function vOn(value) {
}
function createInvoker(initialValue, instance) {
const invoker = (e) => {
callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, [e]);
let args = [e];
if (e.detail && e.detail.__args__) {
args = e.detail.__args__;
}
callWithAsyncErrorHandling(patchStopImmediatePropagation(e, invoker.value), instance, 5 /* NATIVE_EVENT_HANDLER */, args);
};
invoker.value = initialValue;
return invoker;
......
......@@ -38,16 +38,26 @@ export function vOn(value: EventValue | undefined) {
return name
}
interface MPEvent extends Event {
detail: {
__args__?: unknown[]
}
}
function createInvoker(
initialValue: EventValue,
instance: ComponentInternalInstance | null
) {
const invoker: Invoker = (e: Event) => {
let args: unknown[] = [e]
if ((e as MPEvent).detail && (e as MPEvent).detail.__args__) {
args = (e as MPEvent).detail.__args__!
}
callWithAsyncErrorHandling(
patchStopImmediatePropagation(e, invoker.value),
instance,
ErrorCodes.NATIVE_EVENT_HANDLER,
[e]
args
)
}
invoker.value = initialValue
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册