File tree Expand file tree Collapse file tree 3 files changed +41
-5
lines changed
test/unit/specs/directives/public Expand file tree Collapse file tree 3 files changed +41
-5
lines changed Original file line number Diff line number Diff line change @@ -488,7 +488,8 @@ function checkComponent (el, options) {
488
488
*/
489
489
490
490
function checkTerminalDirectives ( el , options ) {
491
- if ( _ . attr ( el , 'pre' ) !== null ) {
491
+ if ( _ . attr ( el , 'pre' ) !== null ||
492
+ el . hasAttribute ( config . prefix + 'else' ) ) {
492
493
return skip
493
494
}
494
495
var value , dirName
Original file line number Diff line number Diff line change @@ -8,6 +8,13 @@ module.exports = {
8
8
bind : function ( ) {
9
9
var el = this . el
10
10
if ( ! el . __vue__ ) {
11
+ // check else block
12
+ var next = el . nextElementSibling
13
+ if ( next && _ . attr ( next , 'else' ) !== null ) {
14
+ _ . remove ( next )
15
+ this . elseFactory = new FragmentFactory ( this . vm , next )
16
+ }
17
+ // check main block
11
18
this . anchor = _ . createAnchor ( 'v-if' )
12
19
_ . replace ( el , this . anchor )
13
20
this . factory = new FragmentFactory ( this . vm , el )
@@ -32,15 +39,25 @@ module.exports = {
32
39
} ,
33
40
34
41
insert : function ( ) {
42
+ if ( this . elseFrag ) {
43
+ this . elseFrag . remove ( )
44
+ this . elseFrag . destroy ( )
45
+ this . elseFrag = null
46
+ }
35
47
this . frag = this . factory . create ( this . _host , this . _scope , this . _frag )
36
48
this . frag . before ( this . anchor )
37
49
} ,
38
50
39
51
remove : function ( ) {
40
- if ( ! this . frag ) return
41
- this . frag . remove ( )
42
- this . frag . destroy ( )
43
- this . frag = null
52
+ if ( this . frag ) {
53
+ this . frag . remove ( )
54
+ this . frag . destroy ( )
55
+ this . frag = null
56
+ }
57
+ if ( this . elseFactory ) {
58
+ this . elseFrag = this . elseFactory . create ( this . _host , this . _scope , this . _frag )
59
+ this . elseFrag . before ( this . anchor )
60
+ }
44
61
} ,
45
62
46
63
unbind : function ( ) {
Original file line number Diff line number Diff line change @@ -396,5 +396,23 @@ if (_.inBrowser) {
396
396
expect ( parentA ) . toBe ( parentB )
397
397
} )
398
398
399
+ it ( 'if + else' , function ( done ) {
400
+ var vm = new Vue ( {
401
+ el : el ,
402
+ data : { test : false , a : 'A' , b : 'B' } ,
403
+ template : '<div v-if="test">{{a}}</div><div v-else>{{b}}</div>'
404
+ } )
405
+ expect ( el . textContent ) . toBe ( 'B' )
406
+ vm . test = true
407
+ _ . nextTick ( function ( ) {
408
+ expect ( el . textContent ) . toBe ( 'A' )
409
+ vm . test = false
410
+ _ . nextTick ( function ( ) {
411
+ expect ( el . textContent ) . toBe ( 'B' )
412
+ done ( )
413
+ } )
414
+ } )
415
+ } )
416
+
399
417
} )
400
418
}
You can’t perform that action at this time.
0 commit comments