26 lines
605 B
TypeScript
26 lines
605 B
TypeScript
import { defineStore } from 'pinia';
|
|
|
|
export const useAlertStore = defineStore('alert', {
|
|
state: () => ({
|
|
message: '',
|
|
type: 'info' as 'success' | 'error' | 'info' | 'warning',
|
|
visible: false,
|
|
}),
|
|
|
|
actions: {
|
|
showAlert(msg: string, type: 'success' | 'error' | 'info' | 'warning' = 'info') {
|
|
this.message = msg;
|
|
this.type = type;
|
|
this.visible = true;
|
|
|
|
// Auto-hide after 3 seconds (optional)
|
|
setTimeout(() => this.hideAlert(), 3000);
|
|
},
|
|
|
|
hideAlert() {
|
|
this.visible = false;
|
|
this.message = '';
|
|
},
|
|
},
|
|
});
|