diff --git a/packages/compiler-core/src/transforms/vModel.ts b/packages/compiler-core/src/transforms/vModel.ts
index f168c181803..598c1ea4387 100644
--- a/packages/compiler-core/src/transforms/vModel.ts
+++ b/packages/compiler-core/src/transforms/vModel.ts
@@ -31,7 +31,7 @@ export const transformModel: DirectiveTransform = (dir, node, context) => {
// we assume v-model directives are always parsed
// (not artificially created by a transform)
- const rawExp = exp.loc.source
+ const rawExp = exp.loc.source.trim()
const expString =
exp.type === NodeTypes.SIMPLE_EXPRESSION ? exp.content : rawExp
diff --git a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
index bf40b0529d4..7fcc1d39506 100644
--- a/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
+++ b/packages/compiler-sfc/__tests__/__snapshots__/compileScript.spec.ts.snap
@@ -1084,6 +1084,29 @@ return (_ctx, _cache) => {
}"
`;
+exports[`SFC compile
+
+
+
+ `,
+ { inlineTemplate: true },
+ )
+ expect(content).toMatch(`_isRef(count) ? (count).value = $event : null`)
+ assertCode(content)
+ })
+
test('v-model should not generate ref assignment code for non-setup bindings', () => {
const { content } = compile(
`