diff --git a/src/compiler/directives/model.js b/src/compiler/directives/model.js
index 39bdbfda4c2..c7a4c09b574 100644
--- a/src/compiler/directives/model.js
+++ b/src/compiler/directives/model.js
@@ -25,7 +25,7 @@ export function genComponentModel (
el.model = {
value: `(${value})`,
- expression: `"${value}"`,
+ expression: JSON.stringify(value),
callback: `function (${baseValueExpression}) {${assignment}}`
}
}
diff --git a/test/unit/modules/compiler/codegen.spec.js b/test/unit/modules/compiler/codegen.spec.js
index 8525e42421c..e7eedec98f6 100644
--- a/test/unit/modules/compiler/codegen.spec.js
+++ b/test/unit/modules/compiler/codegen.spec.js
@@ -151,6 +151,27 @@ describe('codegen', () => {
)
})
+ it('generate v-model directive', () => {
+ assertCodegen(
+ '',
+ `with(this){return _c('input',{directives:[{name:"model",rawName:"v-model",value:(test),expression:"test"}],domProps:{"value":(test)},on:{"input":function($event){if($event.target.composing)return;test=$event.target.value}}})}`
+ )
+ })
+
+ it('generate multiline v-model directive', () => {
+ assertCodegen(
+ '',
+ `with(this){return _c('input',{directives:[{name:"model",rawName:"v-model",value:(\n test \n),expression:"\\n test \\n"}],domProps:{"value":(\n test \n)},on:{"input":function($event){if($event.target.composing)return;\n test \n=$event.target.value}}})}`
+ )
+ })
+
+ it('generate multiline v-model directive on custom component', () => {
+ assertCodegen(
+ '
{{hello}}