Skip to content

Commit 02bee1b

Browse files
committed
docs: doucment update
docs: doucment update
1 parent 8f26090 commit 02bee1b

File tree

2 files changed

+96
-14
lines changed

2 files changed

+96
-14
lines changed

components/app/index.en-US.md

+47-6
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ Application wrapper for some global usages.
3030
App provides upstream and downstream method calls through `provide/inject`, because useApp needs to be used as a subcomponent, we recommend encapsulating App at the top level in the application.
3131

3232
```html
33+
/*myPage.vue*/
3334
<template>
3435
<a-space>
3536
<a-button type="primary" @click="showMessage">Open message</a-button>
@@ -66,7 +67,18 @@ App provides upstream and downstream method calls through `provide/inject`, beca
6667

6768
Note: App.useApp must be available under App.
6869

69-
### 与 ConfigProvider 先后顺序
70+
#### Embedded usage scenarios (if not necessary, try not to do nesting)
71+
72+
```html
73+
<a-app>
74+
<a-space>
75+
...
76+
<a-app>...</a-app>
77+
</a-space>
78+
</a-app>
79+
```
80+
81+
#### Sequence with ConfigProvider
7082

7183
The App component can only use the token in the `ConfigProvider`, if you need to use the Token, the ConfigProvider and the App component must appear in pairs.
7284

@@ -76,13 +88,42 @@ The App component can only use the token in the `ConfigProvider`, if you need to
7688
</a-config-provider>
7789
```
7890

79-
### Embedded usage scenarios (if not necessary, try not to do nesting)
91+
#### Global scene (pinia scene)
92+
93+
```ts
94+
import { App } from 'ant-design-vue';
95+
import type { MessageInstance } from 'ant-design-vue/es/message/interface';
96+
import type { ModalStaticFunctions } from 'ant-design-vue/es/modal/confirm';
97+
import type { NotificationInstance } from 'ant-design-vue/es/notification/interface';
98+
99+
export const useGloablStore = defineStore('global', () => {
100+
const message: MessageInstance = ref();
101+
const notification: NotificationInstance = ref();
102+
const modal: Omit<ModalStaticFunctions, 'warn'> = ref();
103+
(() => {
104+
const staticFunction = App.useApp();
105+
message.value = staticFunction.message;
106+
modal.value = staticFunction.modal;
107+
notification.value = staticFunction.notification;
108+
})();
109+
110+
return { message, notification, modal };
111+
});
112+
```
80113

81114
```html
82-
<a-app>
115+
// sub page
116+
<template>
83117
<a-space>
84-
...
85-
<a-app>...</a-app>
118+
<a-button type="primary" @click="showMessage">Open message</a-button>
86119
</a-space>
87-
</a-app>
120+
</template>
121+
122+
<script setup>
123+
import { useGlobalStore } from '@/stores/global';
124+
const global = useGlobalStore();
125+
const showMessage = () => {
126+
global.message.success('Success!');
127+
};
128+
</script>
88129
```

components/app/index.zh-CN.md

+49-8
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*JGb3RIzyOCkAAA
2121

2222
| 参数 | 说明 | 类型 | 默认值 | 版本 |
2323
| --- | --- | --- | --- | --- |
24-
| message | App 内 Message 的全局配置 | [MessageConfig](/components/message/#messageconfig) | - | 4.x |
25-
| notification | App 内 Notification 的全局配置 | [NotificationConfig](/components/notification/#notificationconfig) | - | 4.x |
24+
| message | App 内 Message 的全局配置 | [MessageConfig](/components/message-cn/#messageconfig) | - | 4.x |
25+
| notification | App 内 Notification 的全局配置 | [NotificationConfig](/components/notification-cn/#notificationconfig) | - | 4.x |
2626

2727
## 如何使用
2828

@@ -31,6 +31,7 @@ coverDark: https://mdn.alipayobjects.com/huamei_7uahnr/afts/img/A*JGb3RIzyOCkAAA
3131
App 组件通过 `provide/inject` 提供上下文方法调用,因而 useApp 需要作为子组件才能使用,我们推荐在应用中顶层包裹 App。
3232

3333
```html
34+
/*myPage.vue*/
3435
<template>
3536
<a-space>
3637
<a-button type="primary" @click="showMessage">Open message</a-button>
@@ -67,7 +68,18 @@ App 组件通过 `provide/inject` 提供上下文方法调用,因而 useApp
6768

6869
注意:App.useApp 必须在 App 之下方可使用。
6970

70-
### 与 ConfigProvider 先后顺序
71+
#### 内嵌使用场景(如无必要,尽量不做嵌套)
72+
73+
```html
74+
<a-app>
75+
<a-space>
76+
...
77+
<a-app>...</a-app>
78+
</a-space>
79+
</a-app>
80+
```
81+
82+
#### 与 ConfigProvider 先后顺序
7183

7284
App 组件只能在 `ConfigProvider` 之下才能使用 Design Token, 如果需要使用其样式重置能力,则 ConfigProvider 与 App 组件必须成对出现。
7385

@@ -77,13 +89,42 @@ App 组件只能在 `ConfigProvider` 之下才能使用 Design Token, 如果
7789
</a-config-provider>
7890
```
7991

80-
### 内嵌使用场景(如无必要,尽量不做嵌套)
92+
#### 全局场景 (pinia 场景)
93+
94+
```ts
95+
import { App } from 'ant-design-vue';
96+
import type { MessageInstance } from 'ant-design-vue/es/message/interface';
97+
import type { ModalStaticFunctions } from 'ant-design-vue/es/modal/confirm';
98+
import type { NotificationInstance } from 'ant-design-vue/es/notification/interface';
99+
100+
export const useGloablStore = defineStore('global', () => {
101+
const message: MessageInstance = ref();
102+
const notification: NotificationInstance = ref();
103+
const modal: Omit<ModalStaticFunctions, 'warn'> = ref();
104+
(() => {
105+
const staticFunction = App.useApp();
106+
message.value = staticFunction.message;
107+
modal.value = staticFunction.modal;
108+
notification.value = staticFunction.notification;
109+
})();
110+
111+
return { message, notification, modal };
112+
});
113+
```
81114

82115
```html
83-
<a-app>
116+
// sub page
117+
<template>
84118
<a-space>
85-
...
86-
<a-app>...</a-app>
119+
<a-button type="primary" @click="showMessage">Open message</a-button>
87120
</a-space>
88-
</a-app>
121+
</template>
122+
123+
<script setup>
124+
import { useGlobalStore } from '@/stores/global';
125+
const global = useGlobalStore();
126+
const showMessage = () => {
127+
global.message.success('Success!');
128+
};
129+
</script>
89130
```

0 commit comments

Comments
 (0)