Skip to content

Commit

Permalink
fix(model): fix dynamic v-model with v-else-if statement
Browse files Browse the repository at this point in the history
  • Loading branch information
gebilaoxiong committed Oct 30, 2017
1 parent 052c53a commit c2b52ac
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/platforms/web/compiler/modules/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
const ifCondition = getAndRemoveAttr(el, 'v-if', true)
const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : ``
const hasElse = getAndRemoveAttr(el, 'v-else', true) != null
const elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true)
// 1. checkbox
const branch0 = cloneASTElement(el)
// process for on the main node
Expand Down Expand Up @@ -63,6 +64,8 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {

if (hasElse) {
branch0.else = true
} else if (elseIfCondition) {
branch0.elseif = elseIfCondition
}

return branch0
Expand Down
25 changes: 25 additions & 0 deletions test/unit/features/directives/model-dynamic.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,31 @@ describe('Directive v-model dynamic input type', () => {
assertInputWorks(vm).then(done)
})

it('with v-else-if', done => {
const vm = new Vue({
data: {
foo: true,
bar: false,
type: null,
test: 'b'
},
template: `<div v-if="foo">text</div><input v-else-if="bar" :type="type" v-model="test">`
}).$mount()
document.body.appendChild(vm.$el)

const chain = waitForUpdate(() => {
expect(vm.$el.textContent).toBe('text')
}).then(() => {
vm.foo = false
}).then(() => {
expect(vm._vnode.isComment).toBe(true)
}).then(() => {
vm.bar = true
})

assertInputWorks(vm, chain).then(done)
})

it('with v-for', done => {
const vm = new Vue({
data: {
Expand Down

0 comments on commit c2b52ac

Please sign in to comment.