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
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 3 deletions

View File

@ -119,7 +119,7 @@ Dialog.confirm({
### 全局方法
通过 `app.use` 注册 Dialog 组件后,会自动在 app 的所有子组件上挂载 `$dialog` 方法,在所有组件内部都可以直接调用此方法。
通过 `app.use` 全局注册 Dialog 组件后,会自动在 app 的所有子组件上挂载 `$dialog` 方法,在所有组件内部都可以直接调用此方法。
```js
export default {
@ -131,6 +131,8 @@ export default {
};
```
> Tips: 由于 setup 选项中无法访问 this因此不能使用上述方式请通过 import 引入。
### 组件调用
如果需要在弹窗内嵌入组件或其他自定义内容,可以使用组件调用的方式。

View File

@ -79,7 +79,7 @@ Notify({
### 全局方法
通过 `app.use` 注册 Notify 组件后,会自动在 app 的所有子组件上挂载 `$notify` 方法,便于在组件内调用。
通过 `app.use` 全局注册 Notify 组件后,会自动在 app 的所有子组件上挂载 `$notify` 方法,便于在组件内调用。
```js
export default {
@ -89,6 +89,8 @@ export default {
};
```
> Tips: 由于 setup 选项中无法访问 this因此不能使用上述方式请通过 import 引入。
### 组件调用
如果需要在 Notify 内嵌入组件或其他自定义内容,可以使用组件调用的方式。

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可以参考下面的示例