From 3d449376d557c4533a9664f95df3a168ecee9bfa Mon Sep 17 00:00:00 2001 From: Andrew Hyndman <43152655+andrew-humu@users.noreply.github.com> Date: Tue, 11 Dec 2018 07:27:43 -0800 Subject: [PATCH] fix(v-model): properly handle multiline v-model expressions (#9184) fix #9183 --- src/compiler/directives/model.js | 2 +- test/unit/modules/compiler/codegen.spec.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) 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( + '', + `with(this){return _c('my-component',{model:{value:(\n test \n),callback:function ($$v) {\n test \n=$$v},expression:"\\n test \\n"}})}` + ) + }) + it('generate template tag', () => { assertCodegen( '
',