import { defineStore } from 'pinia' export interface ToastItem { id: number msg: string type: 'info' | 'ok' | 'err' } let seq = 0 export const useToastStore = defineStore('toast', { state: () => ({ items: [] as ToastItem[] }), actions: { push(msg: string, type: ToastItem['type'] = 'info') { const id = ++seq this.items.push({ id, msg, type }) setTimeout(() => this.remove(id), 4000) }, ok(msg: string) { this.push(msg, 'ok') }, err(msg: string) { this.push(msg, 'err') }, remove(id: number) { this.items = this.items.filter((i) => i.id !== id) }, }, })