You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
Copy file name to clipboardExpand all lines: src/v2/guide/components.md
+20-5Lines changed: 20 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -971,12 +971,12 @@ In a child component, pass data into a slot as if you are passing props to a com
971
971
</div>
972
972
```
973
973
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:
975
975
976
976
```html
977
977
<divclass="parent">
978
978
<child>
979
-
<templatescope="props">
979
+
<templateslot-scope="props">
980
980
<span>hello from parent</span>
981
981
<span>{{ props.text }}</span>
982
982
</template>
@@ -995,14 +995,19 @@ If we render the above, the output will be:
995
995
</div>
996
996
```
997
997
998
+
> In 2.5.0+, `slot-scope` is no longer limited to `<template>` and can be used on any element or component.
999
+
998
1000
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:
999
1001
1000
1002
```html
1001
1003
<my-awesome-list:items="items">
1002
1004
<!-- scoped slot can be named too -->
1003
-
<templateslot="item"scope="props">
1004
-
<liclass="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>
1006
1011
</my-awesome-list>
1007
1012
```
1008
1013
@@ -1018,6 +1023,16 @@ And the template for the list component:
1018
1023
</ul>
1019
1024
```
1020
1025
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
+
<spanslot-scope="{ text }">{{ text }}</span>
1033
+
</child>
1034
+
```
1035
+
1021
1036
## Dynamic Components
1022
1037
1023
1038
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