Skip to content

Commit d8fd6c4

Browse files
ycs77PeachScript
authored andcommitted
docs: deprecated slot special attributes, use v-slot directives (PeachScript#238)
* chore: update vue version * docs: deprecated slot special attributes, prefer v-slot directives
1 parent ccf1a20 commit d8fd6c4

7 files changed

+52
-36
lines changed

docs/api/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ The component will be reset if this property has changed, just like recreating a
5858

5959
## Slots
6060

61-
The contents for these slots can be configured via the [`slot` special attribute](https://vuejs.org/v2/api/index.html#slot), also can be configure via the plugin API.
61+
::: warning
62+
Vue.js [deprecated slot special attributes](https://vuejs.org/v2/api/#slot-deprecated) after v2.6.0, it is recommended to use the [v-slot directive](https://vuejs.org/v2/api/#v-slot).
63+
:::
64+
65+
The contents for these slots can be configured via the [`v-slot` directives](https://vuejs.org/v2/api/#v-slot), also can be configure via the plugin API.
6266

6367
- See also:
6468
- [Configure Load Messages](../guide/configure-load-msg.md)

docs/guide/configure-load-msg.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ Only the `spinner` slot can be configured via the prop, and the set value can on
1616

1717
You can preview all built-in spinner types on the right. Please use other ways if you want to create your own spinner.
1818

19-
## Via `slot` Sepcial Attribute
19+
## Via `v-slot` Directive
2020

21-
We can use the [`slot` special attribute](https://vuejs.org/v2/api/index.html#slot) to configure them:
21+
::: warning
22+
Vue.js [deprecated slot special attributes](https://vuejs.org/v2/api/#slot-deprecated) after v2.6.0, it is recommended to use the [v-slot directive](https://vuejs.org/v2/api/#v-slot).
23+
:::
24+
25+
We can use the [`v-slot` directive] (https:// Vuejs.org/v2/api/#v-slot) to configure them:
2226

2327
``` html
2428
<infinite-loading>
25-
<div slot="spinner">Loading...</div>
26-
<div slot="no-more">No more message</div>
27-
<div slot="no-results">No results message</div>
29+
<div v-slot:spinner>Loading...</div>
30+
<div v-slot:no-more>No more message</div>
31+
<div v-slot:no-results>No results message</div>
2832
</infinite-loading>
2933
```
3034

31-
Unlike other slots, the default value for the `error` slot will provide a retry button for users to load the data again. If you want to implement a retry button for users when you customize the `error` slot, you can use the [`slot-scope`](https://vuejs.org/v2/api/index.html#slot-scope) feature, like this:
35+
Unlike other slots, the default value for the `error` slot will provide a retry button for users to load the data again. If you want to implement a retry button for users when you customize the `error` slot, you can receive the retry method `trigger` in prop and inject it into the retry button. like this:
3236

3337
``` html
3438
<infinite-loading>
35-
<div slot="error" slot-scope="{ trigger }">
36-
Error message, click <a href="javascript:;" @click="trigger">here</a> to retry
39+
<div v-slot:error="{ trigger }">
40+
Error message, click <a href="#retry" @click.prevent="trigger">here</a> to retry
3741
</div>
3842
</infinite-loading>
3943
```
@@ -42,13 +46,13 @@ Unlike other slots, the default value for the `error` slot will provide a retry
4246

4347
In order to maintain consistent behavior for all load messages when we are building a large application, this plugin supports configuration on all slots using the plugin API. We just need to pass a string or Vue component to it, click [here](./configure-plugin-opts.md#slots) to read more about that.
4448

45-
The `error` slot is still special in this way. Just as with the `slot` special attribute, if you want to implement a retry button for users in your own error component, you can use the [`vm.$attrs`](https://cn.vuejs.org/v2/api/#vm-attrs) property, like this:
49+
The `error` slot is still special in this way. Just as with the `v-slot` directive, if you want to implement a retry button for users in your own error component, you can use the [`vm.$attrs`](https://cn.vuejs.org/v2/api/#vm-attrs) property, like this:
4650

4751
``` html
4852
<!-- your own error component -->
4953
<div>
5054
Error message, click
51-
<a href="javascript:;" @click="$attrs.trigger">here</a>
55+
<a href="#retry" @click.prevent="$attrs.trigger">here</a>
5256
to retry
5357
</div>
5458
```
@@ -68,12 +72,12 @@ export default {
6872

6973
## About Hide & Default Styles
7074

71-
For easy use, this component provides some default styles (`font-size`, `color` and `padding`) for slot content. If you want to keep all default styles when you configure via the `slot` special attribute, you have to wrap the content with a `template` tag:
75+
For easy use, this component provides some default styles (`font-size`, `color` and `padding`) for slot content. If you want to keep all default styles when you configure via the `v-slot` directive, you have to wrap the content with a `template` tag:
7276

7377
``` html
7478
<infinite-loading>
7579
<!-- The no-more message will has default styles -->
76-
<template slot="no-more">No more message</template>
80+
<template v-slot:no-more>No more message</template>
7781
</infinite-loading>
7882

7983
```
@@ -83,7 +87,7 @@ If you want to hide a slot, you can create an empty element that is not a `templ
8387
``` html
8488
<infinite-loading>
8589
<!-- The no-more slot will not be displayed -->
86-
<span slot="no-more"></span>
90+
<span v-slot:no-more></span>
8791
</infinite-loading>
8892
```
8993

@@ -92,7 +96,7 @@ If you want to remove all default styles to avoid affecting your own styles, you
9296
``` html
9397
<infinite-loading>
9498
<!-- The no-more message will has no default styles -->
95-
<div slot="no-more">No more message</div>
99+
<div v-slot:no-more>No more message</div>
96100
</infinite-loading>
97101
```
98102

docs/guide/use-with-el-table.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The final template should be similar to:
2323
<!-- el-table-column items -->
2424

2525
<infinite-loading
26-
slot="append"
26+
v-slot:append
2727
@infinite="infiniteHandler"
2828
force-use-infinite-wrapper=".el-table__body-wrapper">
2929
</infinite-loading>

docs/zh/api/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ sidebar: auto
5858

5959
## 插槽
6060

61-
插槽的内容可以通过 `Vue.js` 官方提供的 [`slot` 特殊属性](https://vuejs.org/v2/api/index.html#slot)进行设置,也可以通过插件 API 进行全局设置。
61+
::: warning
62+
Vue.js 官方于 v2.6.0 后[废弃 slot 特殊特性](https://cn.vuejs.org/v2/api/#slot-废弃),推荐使用[v-slot 指令](https://cn.vuejs.org/v2/api/#v-slot)
63+
:::
64+
65+
插槽的内容可以通过 `Vue.js` 官方提供的[`v-slot` 指令](https://cn.vuejs.org/v2/api/#v-slot)进行设置,也可以通过插件 API 进行全局设置。
6266

6367
- 参考:
6468
- [配置加载提示](../guide/configure-load-msg.md)

docs/zh/guide/configure-load-msg.md

+18-14
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,28 @@ previewLink: //jsfiddle.net/PeachScript/94kL0bvs/embedded/result/
1616

1717
你可以在右边预览所有内置加载动画,如果你希望创建自己的加载动画,请使用其他方式。
1818

19-
## 通过 `slot` 特殊属性
19+
## 通过 `v-slot` 指令
2020

21-
我们可以通过 [`slot` 特殊属性](https://vuejs.org/v2/api/index.html#slot)来配置它们:
21+
::: warning
22+
Vue.js 官方于 v2.6.0 后[废弃 slot 特殊特性](https://cn.vuejs.org/v2/api/#slot-废弃),推荐使用[v-slot 指令](https://cn.vuejs.org/v2/api/#v-slot)
23+
:::
24+
25+
我们可以通过[`v-slot` 指令](https://cn.vuejs.org/v2/api/#v-slot)来配置它们:
2226

2327
``` html
2428
<infinite-loading>
25-
<div slot="spinner">Loading...</div>
26-
<div slot="no-more">No more message</div>
27-
<div slot="no-results">No results message</div>
29+
<div v-slot:spinner>Loading...</div>
30+
<div v-slot:no-more>No more message</div>
31+
<div v-slot:no-results>No results message</div>
2832
</infinite-loading>
2933
```
3034

31-
与其他插槽不同的是,`error` 插槽的默认值除了会提供文字信息之外,还会提供一个重试按钮供用户重新尝试加载;在自定义 `error` 插槽时,如果你也希望提供一个重试按钮给用户,可以使用 [`slot-scope`](https://vuejs.org/v2/api/index.html#slot-scope) 功能实现,就像下面这样:
35+
与其他插槽不同的是,`error` 插槽的默认值除了会提供文字信息之外,还会提供一个重试按钮供用户重新尝试加载;在自定义 `error` 插槽时,如果你也希望提供一个重试按钮给用户,可以接收 prop 中的重試的方法 `trigger` 並注入到按鈕,就像下面这样:
3236

3337
``` html
3438
<infinite-loading>
35-
<div slot="error" slot-scope="{ trigger }">
36-
Error message, click <a href="javascript:;" @click="trigger">here</a> to retry
39+
<div v-slot:error="{ trigger }">
40+
Error message, click <a href="#retry" @click.prevent="trigger">here</a> to retry
3741
</div>
3842
</infinite-loading>
3943
```
@@ -42,13 +46,13 @@ previewLink: //jsfiddle.net/PeachScript/94kL0bvs/embedded/result/
4246

4347
在我们构建大型应用时,为了保证所有加载提示的行为一致,此插件支持通过插件 API 统一配置所有的插槽内容,我们只需要传递一个字符串或者 Vue 组件给它就可以了,点击[这里](./configure-plugin-opts.md#插槽)了解更多。
4448

45-
在这里 `error` 插槽仍然是最特殊的哪一个,和使用 `slot` 特殊属性一样,如果你希望提供一个重试按钮给用户,你可以使用 [`vm.$attrs`](https://cn.vuejs.org/v2/api/#vm-attrs) 属性,就像这样:
49+
在这里 `error` 插槽仍然是最特殊的哪一个,和使用 `v-slot` 指令一样,如果你希望提供一个重试按钮给用户,你可以使用 [`vm.$attrs`](https://cn.vuejs.org/v2/api/#vm-attrs) 属性,就像这样:
4650

4751
``` html
4852
<!-- your own error component -->
4953
<div>
5054
Error message, click
51-
<a href="javascript:;" @click="$attrs.trigger">here</a>
55+
<a href="#retry" @click.prevent="$attrs.trigger">here</a>
5256
to retry
5357
</div>
5458
```
@@ -68,12 +72,12 @@ export default {
6872

6973
## 关于隐藏与默认样式
7074

71-
为了便于使用,该组件为插槽内容提供了一些默认样式(`font-size``color``padding`),如果你希望在通过 `slot` 特殊属性配置插槽时保持默认样式的存在,你需要将插槽内容用 `template` 标签包裹:
75+
为了便于使用,该组件为插槽内容提供了一些默认样式(`font-size``color``padding`),如果你希望在通过 `v-slot` 指令配置插槽时保持默认样式的存在,你需要将插槽内容用 `template` 标签包裹:
7276

7377
``` html
7478
<infinite-loading>
7579
<!-- The no-more message will has default styles -->
76-
<template slot="no-more">No more message</template>
80+
<template v-slot:no-more>No more message</template>
7781
</infinite-loading>
7882

7983
```
@@ -83,7 +87,7 @@ export default {
8387
``` html
8488
<infinite-loading>
8589
<!-- The no-more slot will not be displayed -->
86-
<span slot="no-more"></span>
90+
<span v-slot:no-more></span>
8791
</infinite-loading>
8892
```
8993

@@ -92,7 +96,7 @@ export default {
9296
``` html
9397
<infinite-loading>
9498
<!-- The no-more message will has no default styles -->
95-
<div slot="no-more">No more message</div>
99+
<div v-slot:no-more>No more message</div>
96100
</infinite-loading>
97101
```
98102

docs/zh/guide/use-with-el-table.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ previewLink: //jsfiddle.net/PeachScript/uyjb6z34/embedded/result/
2323
<!-- el-table-column items -->
2424

2525
<infinite-loading
26-
slot="append"
26+
v-slot:append
2727
@infinite="infiniteHandler"
2828
force-use-infinite-wrapper=".el-table__body-wrapper">
2929
</infinite-loading>

package.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,16 @@
7777
"postcss-loader": "^3.0.0",
7878
"sinon": "^2.4.1",
7979
"sinon-chai": "^2.13.0",
80-
"vue": "^2.5.17",
81-
"vue-loader": "^15.4.1",
82-
"vue-template-compiler": "^2.5.17",
80+
"vue": "^2.6.10",
81+
"vue-loader": "^15.7.0",
82+
"vue-template-compiler": "^2.6.10",
8383
"vuepress": "^1.0.0-alpha.23",
8484
"webpack": "^4.17.2",
8585
"webpack-cli": "^3.1.0",
8686
"webpack-dev-server": "^3.1.8"
8787
},
8888
"peerDependencies": {
89-
"vue": "^2.2.0"
89+
"vue": "^2.6.10"
9090
},
9191
"license": "MIT",
9292
"browserslist": [

0 commit comments

Comments
 (0)