流浪のwolf

卷帝

导航

vuex 基本代码规范 js 文件

import Vue from "vue";
import Vuex from "vuex";
import { setItem, getItem } from "@/utils/storage";
Vue.use(Vuex);

export default new Vuex.Store({
  state: {
    // 分类
    // allCate: [],
    user: getItem("USERTOKEN"),
  },
  getters: {},
  mutations: {
    setUserToken(state, data) {
      state.user = data;
      // 如果是简单数据不需要序列化 因此封装一个函数
      //   localStorage.setItem("USERTOKEN", JSON.stringify(data));
      setItem("USERTOKEN", data);
    },
  },
  //   在action中发起 axios?
  actions: {},
  modules: {},
});

ps:配合localStore 本地实现token的持久性和全局性存储 ;

posted on 2022-10-18 08:56  流浪のwolf  阅读(14)  评论(0编辑  收藏  举报