import { defineStore } from 'pinia' import fetch from '@/api' export const useStore = defineStore('main', { actions: { logout() { window.location.href = '/' }, get(path, init) { if (!init) { init = {} } return fetch(path, init).catch((err) => { if (err) { this.logout() } }) }, post(path, init) { if (!init) { init = {} } init.method = 'POST' return fetch(path, init).catch((err) => { if (err) { this.logout() } }) } }, persist: true })