Skip to content

Commit 619558b

Browse files
fsx950223Jinjiang
authored andcommitted
Update components.md (vuejs#561)
* Update components.md * Update components.md * Update components.md
1 parent 0bfde7d commit 619558b

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/v2/guide/components.md

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -968,12 +968,12 @@ Vue.component('child-component', {
968968
</div>
969969
```
970970

971-
在父级中,具有特殊特性 `scope``<template>` 元素必须存在,表示它是作用域插槽的模板。`scope` 的值对应一个临时变量名,此变量接收从子组件中传递的 prop 对象:
971+
在父级中,具有特殊特性 `slot-scope``<template>` 元素必须存在,表示它是作用域插槽的模板。`slot-scope` 的值将被用作一个临时变量名,此变量接收从子组件传递过来的 prop 对象:
972972

973973
``` html
974974
<div class="parent">
975975
<child>
976-
<template scope="props">
976+
<template slot-scope="props">
977977
<span>hello from parent</span>
978978
<span>{{ props.text }}</span>
979979
</template>
@@ -992,14 +992,19 @@ Vue.component('child-component', {
992992
</div>
993993
```
994994

995+
> 在 2.5.0+,`slot-scope` 能被用在任意元素或组件中而不再局限于 `<template>`
996+
995997
作用域插槽更典型的用例是在列表组件中,允许使用者自定义如何渲染列表的每一项:
996998

997999
``` html
9981000
<my-awesome-list :items="items">
9991001
 <!-- 作用域插槽也可以是具名的 -->
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>
10031008
</my-awesome-list>
10041009
```
10051010

@@ -1015,6 +1020,16 @@ Vue.component('child-component', {
10151020
</ul>
10161021
```
10171022

1023+
#### 解构
1024+
1025+
`scope-slot` 的值实际上是一个可以出现在函数签名参数位置的合法的 JavaScript 表达式。这意味着在受支持的环境 (单文件组件或现代浏览器) 中,您还可以在表达式中使用 ES2015 解构:
1026+
1027+
``` html
1028+
<child>
1029+
<span slot-scope="{ text }">{{ text }}</span>
1030+
</child>
1031+
```
1032+
10181033
## 动态组件
10191034

10201035
通过使用保留的 `<component>` 元素,动态地绑定到它的 `is` 特性,我们让多个组件可以使用同一个挂载点,并动态切换:

0 commit comments

Comments
 (0)