Skip to content

Commit 0458e2e

Browse files
committed
adjustment: scoped slots must use <template>
1 parent 0b78ea9 commit 0458e2e

File tree

2 files changed

+14
-26
lines changed

2 files changed

+14
-26
lines changed

src/compiler/parser/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,10 @@ export function parse (
169169
if (currentParent && !element.forbidden) {
170170
if (element.else) { // else block
171171
processElse(element, currentParent)
172-
} else if (element.slotTarget && element.slotScope) { // scoped slot
173-
(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[element.slotTarget] = element
172+
} else if (element.slotScope) { // scoped slot
174173
currentParent.plain = false
174+
const name = element.slotTarget || 'default'
175+
;(currentParent.scopedSlots || (currentParent.scopedSlots = {}))[name] = element
175176
} else {
176177
currentParent.children.push(element)
177178
element.parent = currentParent
@@ -356,6 +357,8 @@ function processSlot (el) {
356357
const slotTarget = getBindingAttr(el, 'slot')
357358
if (slotTarget) {
358359
el.slotTarget = slotTarget === '""' ? '"default"' : slotTarget
360+
}
361+
if (el.tag === 'template') {
359362
el.slotScope = getAndRemoveAttr(el, 'scope')
360363
}
361364
}

test/unit/features/component/component-scoped-slot.spec.js

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,13 @@
11
import Vue from 'vue'
22

3-
describe('Component scoped slot', () => {
4-
it('default slot', () => {
5-
const vm = new Vue({
6-
template: `<test><span slot scope="props">{{ props.msg }}</span></test>`,
7-
components: {
8-
test: {
9-
data () {
10-
return { msg: 'hello' }
11-
},
12-
template: `
13-
<div>
14-
<slot :msg="msg"></slot>
15-
</div>
16-
`
17-
}
18-
}
19-
}).$mount()
20-
expect(vm.$el.innerHTML).toBe('<span>hello</span>')
21-
})
22-
23-
it('normal element slot', done => {
3+
fdescribe('Component scoped slot', () => {
4+
it('default slot', done => {
245
const vm = new Vue({
256
template: `
267
<test ref="test">
27-
<span slot="item" scope="props">{{ props.text }}</span>
8+
<template scope="props">
9+
<span>{{ props.msg }}</span>
10+
</template>
2811
</test>
2912
`,
3013
components: {
@@ -34,7 +17,7 @@ describe('Component scoped slot', () => {
3417
},
3518
template: `
3619
<div>
37-
<slot name="item" :text="msg"></slot>
20+
<slot :msg="msg"></slot>
3821
</div>
3922
`
4023
}
@@ -204,7 +187,9 @@ describe('Component scoped slot', () => {
204187
const vm = new Vue({
205188
template: `
206189
<test ref="test">
207-
<span slot="item" scope="props">{{ props.text || 'meh' }}</span>
190+
<template slot="item" scope="props">
191+
<span>{{ props.text || 'meh' }}</span>
192+
</template>
208193
</test>
209194
`,
210195
components: {

0 commit comments

Comments
 (0)