feat: error response interceptor

This commit is contained in:
Methapon2001 2023-11-30 15:36:03 +07:00
parent a27dda4300
commit 3a310ef9db
No known key found for this signature in database
GPG key ID: 849924FEF46BD132
3 changed files with 88 additions and 0 deletions

View file

@ -0,0 +1,28 @@
import { defineStore } from 'pinia'
import { ref } from 'vue'
export const useErrorStore = defineStore('error-data', () => {
const visible = ref<boolean>(false)
const title = ref<string>('')
const msg = ref<string>('')
function set(obj: { title: string; msg: string }, timeout?: number) {
title.value = obj.title
msg.value = obj.msg
show(timeout)
}
function show(timeout: number = -1) {
visible.value = true
if (timeout > 0) {
setTimeout(() => (visible.value = false), timeout)
}
}
function hide() {
visible.value = false
}
return { visible, title, msg, show, hide, set }
})