doc: update doc

pull/4675/head
tangjinzhou 2021-09-18 23:13:08 +08:00
parent 456c35361c
commit 90f273a88e
4 changed files with 82 additions and 7 deletions

View File

@ -56,6 +56,26 @@ Some components use dynamic style to support wave effect. You can config `csp` p
| pageHeader | Unify the ghost of pageHeader ,Ref [pageHeader](<(/components/page-header)> | { ghost:boolean } | 'true' | 1.5.0 |
| transformCellText | Table data can be changed again before rendering. The default configuration of general user empty data. | Function({ text, column, record, index }) => any | - | 1.5.4 |
### ConfigProvider.config() `3.0.0+`
Setting `Modal`、`Message`、`Notification` rootPrefixCls.
```jsx
ConfigProvider.config({
prefixCls: 'ant',
});
```
or
```jsx
// some cinfig support reactively, you can change prefixCls.value = 'other'
const prefixCls = ref('ant');
ConfigProvider.config({
prefixCls,
});
```
## FAQ
#### Does the locale problem still exist in DatePicker even if ConfigProvider `locale` is used?

View File

@ -54,8 +54,29 @@ ConfigProvider 使用 Vue 的 [provide / inject](https://vuejs.org/v2/api/#provi
| getPopupContainer | 弹出框Select, Tooltip, Menu 等等)渲染父节点,默认渲染到 body 上。 | Function(triggerNode, dialogContext) | () => document.body | |
| locale | 语言包配置,语言包可到 [ant-design-vue/es/locale](http://unpkg.com/ant-design-vue/es/locale/) 目录下寻找 | object | - | 1.5.0 |
| pageHeader | 统一设置 pageHeader 的 ghost参考 [pageHeader](<(/components/page-header)>) | { ghost: boolean } | 'true' | 1.5.0 |
| prefixCls | 设置统一样式前缀。注意:需要配合 `less` 变量 `@ant-prefix` 使用 | string | `ant` | |
| transformCellText | Table 数据渲染前可以再次改变,一般用户空数据的默认配置 | Function({ text, column, record, index }) => any | - | 1.5.4 |
### ConfigProvider.config() `3.0.0+`
设置 `Modal`、`Message`、`Notification` rootPrefixCls。
```jsx
ConfigProvider.config({
prefixCls: 'ant',
});
```
or
```jsx
// 如下配置支持响应式数据,你可以通过 prefixCls.value = 'other' 直接改变
const prefixCls = ref('ant');
ConfigProvider.config({
prefixCls,
});
```
## FAQ
#### 为什么我使用了 ConfigProvider `locale`,时间类组件的国际化还有问题?

View File

@ -9,11 +9,7 @@ Modal dialogs.
## When To Use
When requiring users to interact with the application, but without jumping to a new page and interrupting
the user's workflow, you can use `Modal` to create a new floating layer over the current page to get user
feedback or display information.
Additionally, if you need show a simple confirmation dialog, you can use `antd.Modal.confirm()`,
and so on.
When requiring users to interact with the application, but without jumping to a new page and interrupting the user's workflow, you can use `Modal` to create a new floating layer over the current page to get user feedback or display information. Additionally, if you need show a simple confirmation dialog, you can use `antd.Modal.confirm()`, and so on.
## API
@ -89,7 +85,7 @@ The items listed above are all functions, expecting a settings object as paramet
| zIndex | The `z-index` of the Modal | Number | 1000 | |
| onCancel | Specify a function that will be called when the user clicks the Cancel button. The parameter of this function is a function whose execution should include closing the dialog. You can also just return a promise and when the promise is resolved, the modal dialog will also be closed | function | - | |
| onOk | Specify a function that will be called when the user clicks the OK button. The parameter of this function is a function whose execution should include closing the dialog. You can also just return a promise and when the promise is resolved, the modal dialog will also be closed | function | - | |
| parentContext | The parent context of the popup is generally used to get the parent provider, such as the configuration of `ConfigProvider` | vue instance | - | |
| appContext | The context of the pop-up window is generally used to obtain content such as global registered components, vuex, etc. | - | - | |
All the `Modal.method`s will return a reference, and then we can update and close the modal dialog by the reference.
@ -116,3 +112,22 @@ router.beforeEach((to, from, next) => {
Modal.destroyAll();
})
```
## FAQ
### Why can't the Modal method obtain global registered components, context, vuex, etc. and ConfigProvider `locale/prefixCls` configuration, and can't update data responsively?
Call the Modal method directly, and the component will dynamically create a new Vue entity through `Vue.render`. Its context is not the same as the context where the current code is located, so the context information cannot be obtained.
When you need context information (for example, using a globally registered component), you can pass the current component context through the `appContext` property. When you need to keep the property responsive, you can use the function to return:
```tsx
import { getCurrentInstance } from 'vue';
const appContext = getCurrentInstance().appContext;
const title = ref('some message');
Modal.confirm({
title: () => title.value, // the change of title will update the title in confirm synchronously
appContext,
});
```

View File

@ -89,7 +89,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/3StSdUlSH/Modal.svg
| zIndex | 设置 Modal 的 `z-index` | Number | 1000 | |
| onCancel | 取消回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭 | function | 无 | |
| onOk | 点击确定回调,参数为关闭函数,返回 promise 时 resolve 后自动关闭 | function | 无 | |
| parentContext | 弹窗的父级上下文,一般用于获取父级 provider 如获取 `ConfigProvider` 的配置 | vue instance | - | |
| appContext | 弹窗的上下文一般用于获取全局注册组件、vuex 等内容 | - | - | |
以上函数调用后,会返回一个引用,可以通过该引用更新和关闭弹窗。
@ -116,3 +116,22 @@ router.beforeEach((to, from, next) => {
Modal.destroyAll();
})
```
## FAQ
### 为什么 Modal 方法不能获取 全局注册组件、context、vuex 等内容和 ConfigProvider `locale/prefixCls` 配置, 以及不能响应式更新数据
直接调用 Modal 方法,组件会通过 `Vue.render` 动态创建新的 Vue 实体。其 context 与当前代码所在 context 并不相同,因而无法获取 context 信息。
当你需要 context 信息(例如使用全局注册的组件)时,可以通过 `appContext` 属性传递当前组件 context, 当你需要保留属性响应式时,你可以使用函数返回:
```tsx
import { getCurrentInstance } from 'vue';
const appContext = getCurrentInstance().appContext;
const title = ref('some message');
Modal.confirm({
title: () => title.value, // 此时 title 的改变,会同步更新 confirm 中的 title
appContext,
});
```