Skip to content

Commit 59b364a

Browse files
committed
fix slot fallback content scope inside v-for (fix #1282)
1 parent 8d6d010 commit 59b364a

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

src/directives/element/slot.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,11 @@ module.exports = {
6262

6363
compile: function (content, context, host) {
6464
if (content && context) {
65+
var scope = host
66+
? host._scope
67+
: this._scope
6568
this.unlink = context.$compile(
66-
content, host, this.vm._scope, this._frag
69+
content, host, scope, this._frag
6770
)
6871
}
6972
if (content) {

test/unit/specs/directives/element/slot_spec.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@ describe('Slot Distribution', function () {
77
beforeEach(function () {
88
el = document.createElement('div')
99
options = {
10-
el: el
10+
el: el,
11+
data: {
12+
msg: 'self'
13+
}
1114
}
1215
})
1316

@@ -39,10 +42,10 @@ describe('Slot Distribution', function () {
3942
})
4043

4144
it('fallback content', function () {
42-
options.template = '<slot><p>fallback</p></slot>'
45+
options.template = '<slot><p>{{msg}}</p></slot>'
4346
mount()
4447
expect(el.firstChild.tagName).toBe('P')
45-
expect(el.firstChild.textContent).toBe('fallback')
48+
expect(el.firstChild.textContent).toBe('self')
4649
})
4750

4851
it('fallback content with multiple named slots', function () {
@@ -364,4 +367,22 @@ describe('Slot Distribution', function () {
364367
expect(el.textContent).toBe('123234')
365368
})
366369

370+
it('fallback inside v-for', function () {
371+
new Vue({
372+
el: el,
373+
template: '<div v-for="n in 3"><comp></comp></div>',
374+
components: {
375+
comp: {
376+
template: '<div><slot>{{something}}</slot></div>',
377+
data: function () {
378+
return {
379+
something: 'hi'
380+
}
381+
}
382+
}
383+
}
384+
})
385+
expect(el.textContent).toBe('hihihi')
386+
})
387+
367388
})

0 commit comments

Comments
 (0)