File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -968,12 +968,12 @@ Vue.component('child-component', {
968
968
</div >
969
969
```
970
970
971
- 在父级中,具有特殊特性 ` scope ` 的 ` <template> ` 元素必须存在,表示它是作用域插槽的模板。` scope ` 的值对应一个临时变量名,此变量接收从子组件中传递的 prop 对象:
971
+ 在父级中,具有特殊特性 ` slot- scope` 的 ` <template> ` 元素必须存在,表示它是作用域插槽的模板。` slot- scope` 的值将被用作一个临时变量名,此变量接收从子组件传递过来的 prop 对象:
972
972
973
973
``` html
974
974
<div class =" parent" >
975
975
<child >
976
- <template scope =" props" >
976
+ <template slot- scope =" props" >
977
977
<span >hello from parent</span >
978
978
<span >{{ props.text }}</span >
979
979
</template >
@@ -992,14 +992,19 @@ Vue.component('child-component', {
992
992
</div >
993
993
```
994
994
995
+ > 在 2.5.0+,` slot-scope ` 能被用在任意元素或组件中而不再局限于 ` <template> ` 。
996
+
995
997
作用域插槽更典型的用例是在列表组件中,允许使用者自定义如何渲染列表的每一项:
996
998
997
999
``` html
998
1000
<my-awesome-list :items =" items" >
999
1001
<!-- 作用域插槽也可以是具名的 -->
1000
- <template slot =" item" scope =" props" >
1001
- <li class =" my-fancy-item" >{{ props.text }}</li >
1002
- </template >
1002
+ <li
1003
+ slot =" item"
1004
+ slot-scope =" props"
1005
+ class =" my-fancy-item" >
1006
+ {{ props.text }}
1007
+ </li >
1003
1008
</my-awesome-list >
1004
1009
```
1005
1010
@@ -1015,6 +1020,16 @@ Vue.component('child-component', {
1015
1020
</ul >
1016
1021
```
1017
1022
1023
+ #### 解构
1024
+
1025
+ ` scope-slot ` 的值实际上是一个可以出现在函数签名参数位置的合法的 JavaScript 表达式。这意味着在受支持的环境 (单文件组件或现代浏览器) 中,您还可以在表达式中使用 ES2015 解构:
1026
+
1027
+ ``` html
1028
+ <child >
1029
+ <span slot-scope =" { text }" >{{ text }}</span >
1030
+ </child >
1031
+ ```
1032
+
1018
1033
## 动态组件
1019
1034
1020
1035
通过使用保留的 ` <component> ` 元素,动态地绑定到它的 ` is ` 特性,我们让多个组件可以使用同一个挂载点,并动态切换:
You can’t perform that action at this time.
0 commit comments