Vue3 + TS + Antd + Pinia 从零搭建后台系统(三) Pinia + 全局loading + 公共方法

书接上回

本篇主要介绍: Pinia + 全局loading + 公共方法

继续填充

Pinia

想了解Pinia的可看该博主的文章,挺详细的。此篇不做讲解,只讲实际应用
链接: Pinia基础知识

index.ts

import type {
    App } from "vue";
import {
    createPinia } from "pinia";
import piniaPluginPersistedstate from "pinia-plugin-persistedstate";

const store = createPinia() as any;

// 创建Store时,将persistent选项设置为true,则整个Store将使用默认持久化配置保存
store.use(piniaPluginPersistedstate);

export const setupStore = (app: App<Element>) => {
   
  app.use(store);
};

export {
    store };

user.ts 填前文中的坑,补充全局方法:token及login的全局变量及方法

import {
    defineStore } from "pinia";
import {
    store } from "./index";
import {
    UserLoginType, UserType } from "../api/login/types";
import type {
    RouteRecordRaw } from "vue-router";
import {
    Modal } from "ant-design-vue";
import {
    loginOutLocalApi } from "@/api/login";
import router from "@/router";

interface UserState {
   
  userInfo?: UserType;
  tokenKey: string;
  token: string;
  roleRouters?: string[] | AppCustomRouteRecordRaw[];
  rememberMe: boolean;
  loginInfo?: UserLoginType;
}

interface RouteMetaCustom extends Record<string | number | symbol, unknown> {
   
  hidden?: boolean;
  alwaysShow?: boolean;
  title?: string;
  icon?: string;
  noCache?: boolean;
  breadcrumb?: boolean;
  affix?: boolean;
  activeMenu?: string;
  noTagsView?: boolean;
  canTo?: boolean;
  permission?: string[];
}
interface AppCustomRouteRecordRaw extends Omit<RouteRecordRaw, "meta" | "component" | "children"> {
   
  name: string;
  meta: RouteMetaCustom;
  component: string;
  path: string;
  redirect: string;
  children?: AppCustomRouteRecordRaw[];
}
export const useUserStore = defineStore("user", 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值