39 lines
1.0 KiB
Vue
39 lines
1.0 KiB
Vue
<script setup lang="ts">
|
|
import { onBeforeUnmount } from "vue";
|
|
import {
|
|
Button,
|
|
ToastProvider,
|
|
ToastQueue,
|
|
createToastFunction,
|
|
} from "@heroui-vue/components";
|
|
const queue = new ToastQueue();
|
|
const toast = createToastFunction(queue);
|
|
onBeforeUnmount(() => queue.destroy());
|
|
const timers = new Set<ReturnType<typeof setTimeout>>();
|
|
onBeforeUnmount(() => timers.forEach(clearTimeout));
|
|
function show() {
|
|
toast("简单消息");
|
|
for (const [delay, run] of [
|
|
[400, () => toast.success("操作已完成")],
|
|
[800, () => toast.info("有新更新可用")],
|
|
] as const) {
|
|
const timer = setTimeout(() => {
|
|
timers.delete(timer);
|
|
run();
|
|
}, delay);
|
|
timers.add(timer);
|
|
}
|
|
}
|
|
</script>
|
|
<template>
|
|
<div class="flex h-full max-w-xl flex-col items-center justify-center">
|
|
<Button size="sm" variant="secondary" @click="show">显示 3 条 Toast</Button>
|
|
<ToastProvider
|
|
:queue="queue"
|
|
is-expanded
|
|
aria-label="展开的通知"
|
|
to="body"
|
|
/>
|
|
</div>
|
|
</template>
|