Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
forked fromvuejs/vue

Commit0c703e3

Browse files
misoguyyyx990803
authored andcommitted
fix(v-model): v-if / v-else not working with :type + v-model (vuejs#6955)
fixvuejs#6918
1 parentbdcc05a commit0c703e3

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
2929
consttypeBinding:any=getBindingAttr(el,'type')
3030
constifCondition=getAndRemoveAttr(el,'v-if',true)
3131
constifConditionExtra=ifCondition ?`&&(${ifCondition})` :``
32+
consthasElse=getAndRemoveAttr(el,'v-else',true)!=null
33+
constelseIfCondition=getAndRemoveAttr(el,'v-else-if',true)
3234
// 1. checkbox
3335
constbranch0=cloneASTElement(el)
3436
// process for on the main node
@@ -59,6 +61,13 @@ function preTransformNode (el: ASTElement, options: CompilerOptions) {
5961
exp:ifCondition,
6062
block:branch2
6163
})
64+
65+
if(hasElse){
66+
branch0.else=true
67+
}elseif(elseIfCondition){
68+
branch0.elseif=elseIfCondition
69+
}
70+
6271
returnbranch0
6372
}
6473
}

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,48 @@ describe('Directive v-model dynamic input type', () => {
4040
assertInputWorks(vm,chain).then(done)
4141
})
4242

43+
it('with v-else',done=>{
44+
constdata={
45+
ok:true,
46+
type:null,
47+
test:'b'
48+
}
49+
constvm=newVue({
50+
data,
51+
template:`<div v-if="ok">haha</div><input v-else :type="type" v-model="test">`
52+
}).$mount()
53+
document.body.appendChild(vm.$el)
54+
expect(vm.$el.textContent).toBe('haha')
55+
56+
vm.ok=false
57+
assertInputWorks(vm).then(done)
58+
})
59+
60+
it('with v-else-if',done=>{
61+
constvm=newVue({
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+
constchain=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+
4385
it('with v-for',done=>{
4486
constvm=newVue({
4587
data:{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp