10000 2.5: scoped slots · vuejs/v2.vuejs.org@db62039 · GitHub
[go: up one dir, main page]

Skip to content

Commit db62039

Browse files
committed
2.5: scoped slots
1 parent b171877 commit db62039

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/v2/api/index.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,6 +2117,18 @@ type: api
21172117

21182118
- **See also:** [Named Slots](../guide/components.html#Named-Slots)
21192119

2120+
### slot-scope
2121+
2122+
- **Expects:** `function argument expression`
2123+
2124+
- **Usage:**
2125+
2126+
Use to denote an element or component as a scoped slot. The attribute's value should be a valid JavaScript expression that can appear in the argument position of a function signature. This means in supported environments you can also use ES2015 destructuring in the expression.
2127+
2128+
This attribute does not support dynamic binding.
2129+
2130+
- **See also:** [Scoped Slots](../guide/components.html#Scoped-Slots)
2131+
21202132
### is
21212133

21222134
- **Expects:** `string`

src/v2/guide/components.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -971,12 +971,12 @@ In a child component, pass data into a slot as if you are passing props to a com
971971
</div>
972972
```
973973

974-
In the parent, a `<template>` element with a special attribute `scope` must exist, indicating that it is a template for a scoped slot. The value of `scope` is the name of a temporary variable that holds the props object passed from the child:
974+
In the parent, a `<template>` element with a special attribute `slot-scope` must exist, indicating that it is a template for a scoped slot. The value of `slot-scope` will be used as the name of a temporary variable that holds the props object passed from the child:
975975

976976
``` html
977977
<div class="parent">
978978
<child>
979-
<template scope="props">
979+
<template slot-scope="props">
980980
<span>hello from parent</span>
981981
<span>{{ props.text }}</span>
982982
</template>
@@ -995,14 +995,19 @@ If we render the above, the output will be:
995995
</div>
996996
```
997997

998+
> In 2.5.0+, `slot-scope` is no longer limited to `<template>` and can be used on any element or component.
999+
9981000
A more typical use case for scoped slots would be a list component that allows the component consumer to customize how each item in the list should be rendered:
9991001

10001002
``` html
10011003
<my-awesome-list :items="items">
10021004
<!-- scoped slot can be named too -->
1003-
<template slot="item" scope="props">
1004-
<li class="my-fancy-item">{{ props.text }}</li>
1005-
</template>
1005+
<li
1006+
slot="item"
1007+
slot-scope="props"
1008+
class="my-fancy-item">
1009+
{{ props.text }}
1010+
</li>
10061011
</my-awesome-list>
10071012
```
10081013

@@ -1018,6 +1023,16 @@ And the template for the list component:
10181023
</ul>
10191024
```
10201025

1026+
#### Destructuring
1027+
1028+
`scope-slot`'s value is in fact a valid JavaScript expression that can appear in the argument position of a function signature. This means in supported environments (in single-file components or in modern browsers) you can also use ES2015 destructuring in the expression:
1029+
1030+
``` html
1031+
<child>
1032+
<span slot-scope="{ text }">{{ text }}</span>
1033+
</child>
1034+
```
1035+
10211036
## Dynamic Components
10221037

10231038
You can use the same mount point and dynamically switch between multiple components using the reserved `<component>` element and dynamically bind to its `is` attribute:

0 commit comments

Comments
 (0)
0