Skip to content

Commit 3483db2

Browse files
committed
compile v-if content with correct transclusion host (fix #1097)
1 parent eb5c80a commit 3483db2

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

src/directives/if.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ module.exports = {
2727
this.linker = compiler.compile(
2828
this.template,
2929
this.vm.$options,
30-
true
30+
true, // partial
31+
this._host // important
3132
)
3233
cache.put(cacheId, this.linker)
3334
}

test/unit/specs/directives/if_spec.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,5 +327,33 @@ if (_.inBrowser) {
327327
}
328328
})
329329

330+
// #1097 v-if components not having correct parent
331+
it('compile with correct transclusion host', function () {
332+
var parentA
333+
var parentB
334+
new Vue({
335+
el: el,
336+
data: {
337+
show: true
338+
},
339+
template: '<parent><child v-if="show"></child></parent>',
340+
components: {
341+
parent: {
342+
template: '<content></content>',
343+
created: function () {
344+
parentA = this
345+
}
346+
},
347+
child: {
348+
created: function () {
349+
parentB = this.$parent
350+
}
351+
}
352+
}
353+
})
354+
expect(parentA).toBeTruthy()
355+
expect(parentA).toBe(parentB)
356+
})
357+
330358
})
331359
}

0 commit comments

Comments
 (0)