Skip to content

Commit 78fa71c

Browse files
committed
fix vuejs#539 v-if duplicate compile when a different truthy value is set
1 parent ee2ae35 commit 78fa71c

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/directives/if.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ module.exports = {
4343
},
4444

4545
insert: function () {
46+
// avoid duplicate inserts, since update() can be
47+
// called with different truthy values
48+
if (this.decompile) {
49+
return
50+
}
4651
var vm = this.vm
4752
var frag = templateParser.clone(this.template)
4853
var decompile = this.linker(vm, frag)

test/unit/specs/directives/if_spec.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,22 @@ if (_.inBrowser) {
145145
})
146146
})
147147

148+
it('v-if with different truthy values', function (done) {
149+
var vm = new Vue({
150+
el: el,
151+
data: {
152+
a: 1
153+
},
154+
template: '<div v-if="a">{{a}}</div>'
155+
})
156+
expect(el.innerHTML).toBe(wrap('<div>1</div>'))
157+
vm.a = 2
158+
_.nextTick(function () {
159+
expect(el.innerHTML).toBe(wrap('<div>2</div>'))
160+
done()
161+
})
162+
})
163+
148164
it('invalid warn', function () {
149165
el.setAttribute('v-if', 'test')
150166
var vm = new Vue({

0 commit comments

Comments
 (0)