Skip to content

Commit acfd684

Browse files
committed
feat(Message): add Hook demo
1 parent 295e5af commit acfd684

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

components/message/demo/hook.vue

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<docs>
2+
---
3+
order: 10
4+
title:
5+
zh-CN: Hooks 调用(推荐)
6+
en-US: Hooks Usage (Recommend)
7+
---
8+
9+
## zh-CN
10+
11+
通过 `message.useMessage` 创建支持读取 context 的 `contextHolder`。请注意,我们推荐通过顶层注册的方式代替 `message` 静态方法,因为静态方法无法消费上下文,因而 ConfigProvider 的数据也不会生效。
12+
13+
## en-US
14+
15+
Use `message.useMessage` to get `contextHolder` with context accessible issue. Please note that, we recommend to use top level registration instead of `message` static method, because static method cannot consume context, and ConfigProvider data will not work.
16+
17+
</docs>
18+
19+
<template>
20+
<contextHolder />
21+
<a-button type="primary" @click="info">Display normal message</a-button>
22+
</template>
23+
24+
<script lang="ts" setup>
25+
import { message } from 'ant-design-vue';
26+
const [messageApi, contextHolder] = message.useMessage();
27+
28+
const info = () => {
29+
messageApi.info('Hello, Ant Design!');
30+
};
31+
</script>

components/message/demo/index.vue

+3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<template>
22
<demo-sort>
3+
<Hook />
34
<info />
45
<duration />
56
<other />
@@ -20,6 +21,7 @@ import customStyleVue from './custom-style.vue';
2021
import CN from '../index.zh-CN.md';
2122
import US from '../index.en-US.md';
2223
import { defineComponent } from 'vue';
24+
import Hook from './hook.vue';
2325
export default defineComponent({
2426
CN,
2527
US,
@@ -31,6 +33,7 @@ export default defineComponent({
3133
Thenable,
3234
Update,
3335
customStyleVue,
36+
Hook,
3437
},
3538
setup() {
3639
return {};

0 commit comments

Comments
 (0)