Appearance
Notice 通知组件
vue
<script setup lang="ts">
import { getCurrentInstance, h } from 'vue'
import { Notice } from 'npc-ui'
import { IconAlarm } from '@npc-ui/icons'
import Title from './components/Title'
import Content from './components/Content.vue'
// content 渲染组件UI样式失效的解决办法
const instance = getCurrentInstance()
function click() {
Notice.info({
title: '通知',
content: '这是通知内容',
})
}
function click2() {
Notice.info({
title: h(Title),
content: h(Content),
appContext: instance?.appContext,
})
}
function click3() {
Notice.info({
title: h('span', [h(IconAlarm), '警告']),
content: h('div', [
h('p', '重要消息'),
h('p', '请立即处理'),
]),
duration: 0,
})
}
</script>
<template>
<div class="notice-demo">
<p>
<NpButton @click="click">
默认弹框
</NpButton>
</p>
<p>
<NpButton @click="click2">
渲染组件
</NpButton>
</p>
<p>
<NpButton @click="click3">
渲染VNode
</NpButton>
</p>
</div>
</template>
<style>
.notice-demo {
display: flex;
gap: 10px;
}
</style>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63