Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
/corePublic

Commitc9f91d5

Browse files
committed
fix(compiler-vapor): wrap handler values in functions for dynamic v-on
1 parentddc1bae commitc9f91d5

File tree

5 files changed

+12
-5
lines changed

5 files changed

+12
-5
lines changed

‎packages/compiler-vapor/__tests__/transforms/__snapshots__/transformElement.spec.ts.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ exports[`compiler: element transform > component > v-on="obj" 1`] = `
291291
export function render(_ctx){
292292
const_component_Foo=_resolveComponent("Foo")
293293
constn0=_createComponentWithFallback(_component_Foo, { $: [
294-
()=> (_toHandlers(_ctx.obj))
294+
()=> (_toHandlers(_ctx.obj,false,true))
295295
] },null,true)
296296
returnn0
297297
}"

‎packages/compiler-vapor/__tests__/transforms/__snapshots__/transformSlotOutlet.spec.ts.snap‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export function render(_ctx) {
181181
constn0=_createSlot("default", {
182182
onClick: ()=>_ctx.foo,
183183
$: [
184-
()=> (_toHandlers(_ctx.bar)),
184+
()=> (_toHandlers(_ctx.bar,false,true)),
185185
{baz: ()=> (_ctx.qux) }
186186
]
187187
})

‎packages/compiler-vapor/__tests__/transforms/transformElement.spec.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ describe('compiler: element transform', () => {
364364
const{ code, ir}=compileWithElementTransform(`<Foo v-on="obj" />`)
365365
expect(code).toMatchSnapshot()
366366
expect(code).contains(`[
367-
() => (_toHandlers(_ctx.obj))
367+
() => (_toHandlers(_ctx.obj, false, true))
368368
]`)
369369
expect(ir.block.dynamic.children[0].operation).toMatchObject({
370370
type:IRNodeTypes.CREATE_COMPONENT_NODE,

‎packages/compiler-vapor/src/generators/component.ts‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ function genDynamicProps(
219219
expr=genMulti(DELIMITERS_OBJECT,genProp(p,context))
220220
else{
221221
expr=genExpression(p.value,context)
222-
if(p.handler)expr=genCall(helper('toHandlers'),expr)
222+
if(p.handler)
223+
expr=genCall(
224+
helper('toHandlers'),
225+
expr,
226+
`false`,
227+
`true`,// wrap handler values in functions
228+
)
223229
}
224230
}
225231
frags.push(['() => (', ...expr,')'])

‎packages/runtime-core/src/helpers/toHandlers.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { warn } from '../warning'
88
exportfunctiontoHandlers(
99
obj:Record<string,any>,
1010
preserveCaseIfNecessary?:boolean,
11+
needWrap?:boolean,
1112
):Record<string,any>{
1213
constret:Record<string,any>={}
1314
if(__DEV__&&!isObject(obj)){
@@ -19,7 +20,7 @@ export function toHandlers(
1920
preserveCaseIfNecessary&&/[A-Z]/.test(key)
2021
?`on:${key}`
2122
:toHandlerKey(key)
22-
]=obj[key]
23+
]=needWrap ?()=>obj[key] :obj[key]
2324
}
2425
returnret
2526
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp