docs: add tip for using global method in setup (#8647)

This commit is contained in:
neverland
2021-05-02 11:16:14 +08:00
committed by GitHub
parent 4d27e8b969
commit 511b316074
3 changed files with 9 additions and 3 deletions
+3 -1
View File
@@ -107,7 +107,7 @@ const timer = setInterval(() => {
### 全局方法
通过 `app.use` 注册 Toast 组件后,会自动在 app 的所有子组件上挂载 `$toast` 方法,便于在组件内调用。
通过 `app.use` 全局注册 Toast 组件后,会自动在 app 的所有子组件上挂载 `$toast` 方法,便于在组件内调用。
```js
export default {
@@ -117,6 +117,8 @@ export default {
};
```
> Tips: 由于 setup 选项中无法访问 this,因此不能使用上述方式,请通过 import 引入。
### 单例模式
Toast 默认采用单例模式,即同一时间只会存在一个 Toast,如果需要在同一时间弹出多个 Toast,可以参考下面的示例: