123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- // import user from './modules/user.js'
-
-
- Vue.use(Vuex)
- const store = new Vuex.Store({
-
- // state 中存放的就是全局共享的数据
- state: {
- user: {
- appid: 'wxd3bab568bc42d1de',
- token: '',
- code: '123',
- name: '用户',
- phone: '',
- personId: '',
- classId: '',
- sexNumber: null,
- Semester: '',
- sex: '',
- termId: '',
- Classs: ''
- }
- },
-
-
- // Mutation 用户变更Store数据
- mutations: {
- SET_USER_INFO (state, value) {
- state.user = {
- ...state.user,
- ...value
- }
-
- console.log('SET_USER_INFO被修改为:', state.user);
-
-
- },
-
- },
- //Getter用于对Store中的数据进行加工处理,形成新的数据
- getters: {
- completedUserInfo (state) {
- return state.user
- }
-
-
- },
- //Action 是专门用于处理异步任务的
- actions: {
- getUserInfo ({ dispatch, commit }, value) {
- console.log('actions---vaule', value);
- //处理异步还得调用mutations里面的方法修改数据 mutations 不能处理异步
- commit('SET_USER_INFO', value)
- dispatch('SET_USER_INFO', value)
- }
- }
-
-
- });
-
- export default store;
-
-
|