Skip to content

Commit

Permalink
fix(v-model): properly handle multiline v-model expressions (#9184)
Browse files Browse the repository at this point in the history
fix #9183
  • Loading branch information
andrew-humu authored and yyx990803 committed Dec 11, 2018
1 parent d780dd2 commit 3d44937
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/compiler/directives/model.js
Expand Up @@ -25,7 +25,7 @@ export function genComponentModel (

el.model = {
value: `(${value})`,
expression: `"${value}"`,
expression: JSON.stringify(value),
callback: `function (${baseValueExpression}) {${assignment}}`
}
}
Expand Down
21 changes: 21 additions & 0 deletions test/unit/modules/compiler/codegen.spec.js
Expand Up @@ -151,6 +151,27 @@ describe('codegen', () => {
)
})

it('generate v-model directive', () => {
assertCodegen(
'<input v-model="test">',
`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(
'<input v-model="\n test \n">',
`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(
'<my-component v-model="\n test \n" />',
`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(
'<div><template><p>{{hello}}</p></template></div>',
Expand Down

0 comments on commit 3d44937

Please sign in to comment.