[new feature] Toast: support multiple instance (#586)

This commit is contained in:
neverland
2018-01-29 17:19:01 +08:00
committed by GitHub
parent 7f055a4d2d
commit 1f19852118
5 changed files with 115 additions and 56 deletions

View File

@@ -62,6 +62,19 @@ export default {
}
```
#### Singleton
Toast use singleton mode by default, if you need to pop multiple Toast at the same time, you can refer to the following example
```js
Toast.allowMultiple();
const toast1 = Toast('First Toast');
const toast2 = Toast.success('Second Toast');
toast1.clear();
toast2.clear();
```
### Methods
| Methods | Attribute | Return value | Description |
@@ -70,9 +83,10 @@ export default {
| Toast.loading | `options | message` | toast instance | Show loading toast |
| Toast.success | `options | message` | toast instance | Show success toast |
| Toast.fail | `options | message` | toast instance | Show fail toast |
| Toast.clear | `clearAll` | `void` | Close |
| Toast.allowMultiple | - | `void` | Allow multlple toast at the same time |
| Toast.setDefaultOptions | `options` | `void` | Set default options of all toasts |
| Toast.resetDefaultOptions | - | `void` | Reset default options of all toasts |
| Toast.clear | - | `void` | Close |
### Options

View File

@@ -62,6 +62,18 @@ export default {
}
```
#### 单例模式
Toast 默认采用单例模式,即同一时间只会存在一个 Toast如果需要在同一时间弹出多个 Toast可以参考下面的示例
```js
Toast.allowMultiple();
const toast1 = Toast('第一个 Toast');
const toast2 = Toast.success('第二个 Toast');
toast1.clear();
toast2.clear();
```
### 方法
@@ -72,9 +84,10 @@ export default {
| Toast.loading | `options | message` | toast 实例 | 展示加载提示 |
| Toast.success | `options | message` | toast 实例 | 展示成功提示 |
| Toast.fail | `options | message` | toast 实例 | 展示失败提示 |
| Toast.clear | `clearAll` | `void` | 关闭提示 |
| Toast.allowMultiple | - | `void` | 允许同时存在多个 Toast |
| Toast.setDefaultOptions | `options` | `void` | 修改默认配置,对所有 Toast 生效 |
| Toast.resetDefaultOptions | - | `void` | 重置默认配置,对所有 Toast 生效 |
| Toast.clear | - | `void` | 关闭提示 |
### Options