Skip to content

Commit 839a504

Browse files
yyx990803zhangzhonghe
authored andcommitted
fix(v-model): fix incorrect codegen for non-ref bindings
fix vuejs#6241
1 parent b79668f commit 839a504

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/compiler-core/src/transforms/vModel.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
4848
const maybeRef =
4949
!__BROWSER__ &&
5050
context.inline &&
51-
bindingType &&
52-
bindingType !== BindingTypes.SETUP_CONST
51+
(bindingType === BindingTypes.SETUP_LET ||
52+
bindingType === BindingTypes.SETUP_REF ||
53+
bindingType === BindingTypes.SETUP_MAYBE_REF)
5354

5455
if (
5556
!expString.trim() ||

packages/compiler-sfc/__tests__/compileScript.spec.ts

+20
Original file line numberDiff line numberDiff line change
@@ -673,6 +673,26 @@ defineExpose({ foo: 123 })
673673
assertCode(content)
674674
})
675675

676+
test('v-model should not generate ref assignment code for non-setup bindings', () => {
677+
const { content } = compile(
678+
`<script setup>
679+
import { ref } from 'vue'
680+
const count = ref(0)
681+
</script>
682+
<script>
683+
export default {
684+
data() { return { foo: 123 } }
685+
}
686+
</script>
687+
<template>
688+
<input v-model="foo">
689+
</template>
690+
`,
691+
{ inlineTemplate: true }
692+
)
693+
expect(content).not.toMatch(`_isRef(foo)`)
694+
})
695+
676696
test('template assignment expression codegen', () => {
677697
const { content } = compile(
678698
`<script setup>

0 commit comments

Comments
 (0)