Skip to content

Commit 3e8c4d6

Browse files
committed
docs: add hide and default styles explanation for slots
1 parent 08861e3 commit 3e8c4d6

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

docs/assets/schema.png

9.54 KB
Loading

docs/guide/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ npm install vue-infinite-loading -S
1515

1616
### Direct `<script>` Include
1717

18-
After you imported this plugin through `script` tag, it will register `InfiniteLoading` component automatically, so you can use it in globally.
18+
After you imported this plugin through `script` tag, it will register `InfiniteLoading` component automatically, so you can use it in global.
1919

2020
#### CDN
2121

docs/guide/configure-load-msg.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,56 @@ export default {
5151
/* ... */
5252
};
5353
```
54+
55+
## About Hide & Default Styles
56+
57+
For easy to use, this component provide some default styles (`font-size`, `color` and `padding`) for slot content, if you want to keep all default styles when you configure via `slot` special attribute, you have to wrap the content with `template` tag:
58+
59+
``` html
60+
<infinite-loading>
61+
<!-- The no-more message will has default styles -->
62+
<template slot="no-more">No more message</template>
63+
</infinite-loading>
64+
65+
```
66+
67+
If you want to hide a slot, you can create an empty element that is not a `template` element, because the empty `template` element will be ignored by Vue.js:
68+
69+
``` html
70+
<infinite-loading>
71+
<!-- The no-more slot will not be displayed -->
72+
<span slot="no-more"></span>
73+
</infinite-loading>
74+
```
75+
76+
If you want to remove all default styles to avoid affecting your own styles, you can wrap the content with an element that is not a `template` element:
77+
78+
``` html
79+
<infinite-loading>
80+
<!-- The no-more message will has no default styles -->
81+
<div slot="no-more">No more message</div>
82+
</infinite-loading>
83+
```
84+
85+
Almost forgot, if you want to configure slot content globally via plugin API, you can control them like this:
86+
87+
``` js
88+
import Vue from 'vue';
89+
import InfiniteLoading from 'vue-infinite-loading';
90+
import InfiniteError from 'path/to/your/components/InfiniteError',
91+
92+
Vue.use(InfiniteLoading, {
93+
slots: {
94+
// keep default styles
95+
noResults: 'No results message',
96+
97+
// remove default styles
98+
noMore: InfiniteError,
99+
100+
// hide slot
101+
error: {
102+
render: h => h('div'),
103+
},
104+
},
105+
});
106+
```

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

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,56 @@ export default {
5151
/* ... */
5252
};
5353
```
54+
55+
## 关于隐藏与默认样式
56+
57+
为了便于使用,该组件为插槽内容提供了一些默认样式(`font-size``color``padding`),如果你希望在通过 `slot` 特殊属性配置插槽时保持默认样式的存在,你需要将插槽内容用 `template` 标签包裹:
58+
59+
``` html
60+
<infinite-loading>
61+
<!-- The no-more message will has default styles -->
62+
<template slot="no-more">No more message</template>
63+
</infinite-loading>
64+
65+
```
66+
67+
如果你希望隐藏某个插槽,你可以创建一个不是 `template` 标签的空元素,因为 Vue.js 会忽略空的 `template` 元素:
68+
69+
``` html
70+
<infinite-loading>
71+
<!-- The no-more slot will not be displayed -->
72+
<span slot="no-more"></span>
73+
</infinite-loading>
74+
```
75+
76+
如果你希望移除默认样式以避免影响自己的样式,你可以将插槽内容用不是 `template` 标签的元素包裹:
77+
78+
``` html
79+
<infinite-loading>
80+
<!-- The no-more message will has no default styles -->
81+
<div slot="no-more">No more message</div>
82+
</infinite-loading>
83+
```
84+
85+
差点忘了,如果你想通过插件 API 全局配置插槽内容,可以像这样进行控制:
86+
87+
``` js
88+
import Vue from 'vue';
89+
import InfiniteLoading from 'vue-infinite-loading';
90+
import InfiniteError from 'path/to/your/components/InfiniteError',
91+
92+
Vue.use(InfiniteLoading, {
93+
slots: {
94+
// keep default styles
95+
noResults: 'No results message',
96+
97+
// remove default styles
98+
noMore: InfiniteError,
99+
100+
// hide slot
101+
error: {
102+
render: h => h('div'),
103+
},
104+
},
105+
});
106+
```

0 commit comments

Comments
 (0)