Skip to content

Commit c2b52ac

Browse files
committed
fix(model): fix dynamic v-model with v-else-if statement
1 parent 052c53a commit c2b52ac

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

src/platforms/web/compiler/modules/model.js

+3
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
3030
const ifCondition = getAndRemoveAttr(el, 'v-if', true)
3131
const ifConditionExtra = ifCondition ? `&&(${ifCondition})` : ``
3232
const hasElse = getAndRemoveAttr(el, 'v-else', true) != null
33+
const elseIfCondition = getAndRemoveAttr(el, 'v-else-if', true)
3334
// 1. checkbox
3435
const branch0 = cloneASTElement(el)
3536
// process for on the main node
@@ -63,6 +64,8 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
6364

6465
if (hasElse) {
6566
branch0.else = true
67+
} else if (elseIfCondition) {
68+
branch0.elseif = elseIfCondition
6669
}
6770

6871
return branch0

test/unit/features/directives/model-dynamic.spec.js

+25
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ describe('Directive v-model dynamic input type', () => {
5757
assertInputWorks(vm).then(done)
5858
})
5959

60+
it('with v-else-if', done => {
61+
const vm = new Vue({
62+
data: {
63+
foo: true,
64+
bar: false,
65+
type: null,
66+
test: 'b'
67+
},
68+
template: `<div v-if="foo">text</div><input v-else-if="bar" :type="type" v-model="test">`
69+
}).$mount()
70+
document.body.appendChild(vm.$el)
71+
72+
const chain = waitForUpdate(() => {
73+
expect(vm.$el.textContent).toBe('text')
74+
}).then(() => {
75+
vm.foo = false
76+
}).then(() => {
77+
expect(vm._vnode.isComment).toBe(true)
78+
}).then(() => {
79+
vm.bar = true
80+
})
81+
82+
assertInputWorks(vm, chain).then(done)
83+
})
84+
6085
it('with v-for', done => {
6186
const vm = new Vue({
6287
data: {

0 commit comments

Comments
 (0)