Skip to content

Commit

Permalink
fix(v-model): ensure v-model listener casing is consistent with manua…
Browse files Browse the repository at this point in the history
…l v-on listener (vuejs#7067)

fix vuejs#7066
  • Loading branch information
sxzz authored and chrislone committed Feb 4, 2023
1 parent 8c71d3e commit 74f2025
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ return function render(_ctx, _cache) {
const { openBlock: _openBlock, createElementBlock: _createElementBlock } = _Vue
return (_openBlock(), _createElementBlock(\\"input\\", {
value: model,
\\"onUpdate:value\\": $event => ((model) = $event)
}, null, 40 /* PROPS, HYDRATE_EVENTS */, [\\"value\\", \\"onUpdate:value\\"]))
\\"foo-value\\": model,
\\"onUpdate:fooValue\\": $event => ((model) = $event)
}, null, 40 /* PROPS, HYDRATE_EVENTS */, [\\"foo-value\\", \\"onUpdate:fooValue\\"]))
}
}"
`;
Expand Down
6 changes: 3 additions & 3 deletions packages/compiler-core/__tests__/transforms/vModel.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,13 @@ describe('compiler: transform v-model', () => {
})

test('with argument', () => {
const root = parseWithVModel('<input v-model:value="model" />')
const root = parseWithVModel('<input v-model:foo-value="model" />')
const node = root.children[0] as ElementNode
const props = ((node.codegenNode as VNodeCall).props as ObjectExpression)
.properties
expect(props[0]).toMatchObject({
key: {
content: 'value',
content: 'foo-value',
isStatic: true
},
value: {
Expand All @@ -270,7 +270,7 @@ describe('compiler: transform v-model', () => {

expect(props[1]).toMatchObject({
key: {
content: 'onUpdate:value',
content: 'onUpdate:fooValue',
isStatic: true
},
value: {
Expand Down
3 changes: 2 additions & 1 deletion packages/compiler-core/src/transforms/vModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
} from '../utils'
import { IS_REF } from '../runtimeHelpers'
import { BindingTypes } from '../options'
import { camelize } from '@vue/shared'

export const transformModel: DirectiveTransform = (dir, node, context) => {
const { exp, arg } = dir
Expand Down Expand Up @@ -77,7 +78,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
const propName = arg ? arg : createSimpleExpression('modelValue', true)
const eventName = arg
? isStaticExp(arg)
? `onUpdate:${arg.content}`
? `onUpdate:${camelize(arg.content)}`
: createCompoundExpression(['"onUpdate:" + ', arg])
: `onUpdate:modelValue`

Expand Down

0 comments on commit 74f2025

Please sign in to comment.