buddhism/store/index.js
2025-09-05 17:22:40 +08:00

38 lines
878 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import Vuex from "vuex";
import createPersistedState from "vuex-persistedstate";
import user from "./modules/user";
// 导出一个函数来创建 store而不是直接创建实例
export default function createStore() {
return new Vuex.Store({
state: {
formedId: null,
},
mutations: {
SET_FORMED_ID(state, formedId) {
state.formedId = formedId;
},
},
actions: {
async setFormedId({ commit }, formedId) {
commit("SET_FORMED_ID", formedId);
},
},
getters: {},
modules: {
user,
},
plugins: [
createPersistedState({
key: "vuex_store",
storage: {
getItem: (key) => uni.getStorageSync(key),
setItem: (key, value) => uni.setStorageSync(key, value),
removeItem: (key) => uni.removeStorageSync(key),
},
}),
],
});
}