48 lines
1.1 KiB
Vue
48 lines
1.1 KiB
Vue
<script setup lang="ts">
|
|
import { onBeforeUnmount } from "vue";
|
|
import {
|
|
Button,
|
|
ToastProvider,
|
|
createToastFunction,
|
|
ToastQueue,
|
|
type ToastContentValue,
|
|
} from "@heroui-vue/components";
|
|
|
|
const placements = [
|
|
"top start",
|
|
"top",
|
|
"top end",
|
|
"bottom start",
|
|
"bottom",
|
|
"bottom end",
|
|
] as const;
|
|
|
|
// One queue + provider per placement so the toast is actually mounted
|
|
// into that corner of the viewport.
|
|
const instances = placements.map((placement) => {
|
|
const queue = new ToastQueue<ToastContentValue>({ maxVisibleToasts: 2 });
|
|
return { placement, queue, toast: createToastFunction(queue) };
|
|
});
|
|
onBeforeUnmount(() =>
|
|
instances.forEach((instance) => instance.queue.destroy()),
|
|
);
|
|
</script>
|
|
|
|
<template>
|
|
<div class="flex flex-wrap gap-3">
|
|
<template v-for="inst in instances" :key="inst.placement">
|
|
<Button
|
|
variant="secondary"
|
|
@click="inst.toast(`位置:${inst.placement}`, { timeout: 3000 })"
|
|
>
|
|
{{ inst.placement }}
|
|
</Button>
|
|
<ToastProvider
|
|
:queue="inst.queue"
|
|
:placement="inst.placement"
|
|
to="body"
|
|
/>
|
|
</template>
|
|
</div>
|
|
</template>
|