Skip to content

Commit

Permalink
fix vuejs#539 v-if duplicate compile when a different truthy value is…
Browse files Browse the repository at this point in the history
… set
  • Loading branch information
yyx990803 committed Nov 3, 2014
1 parent ee2ae35 commit 78fa71c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/directives/if.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ module.exports = {
},

insert: function () {
// avoid duplicate inserts, since update() can be
// called with different truthy values
if (this.decompile) {
return
}
var vm = this.vm
var frag = templateParser.clone(this.template)
var decompile = this.linker(vm, frag)
Expand Down
16 changes: 16 additions & 0 deletions test/unit/specs/directives/if_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,22 @@ if (_.inBrowser) {
})
})

it('v-if with different truthy values', function (done) {
var vm = new Vue({
el: el,
data: {
a: 1
},
template: '<div v-if="a">{{a}}</div>'
})
expect(el.innerHTML).toBe(wrap('<div>1</div>'))
vm.a = 2
_.nextTick(function () {
expect(el.innerHTML).toBe(wrap('<div>2</div>'))
done()
})
})

it('invalid warn', function () {
el.setAttribute('v-if', 'test')
var vm = new Vue({
Expand Down

0 comments on commit 78fa71c

Please sign in to comment.