123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- import storage from '../common/storage'
- Vue.use(Vuex);
- const store = new Vuex.Store({
- // 属性值
- state: {
- users: storage.getJson("users"),
- currentpage:storage.getJson("pageName"),
- },
- // Mutation 必须是同步函数
- // 更改state属性内容
- // 使用:this.$store.commit("setUserInfo",{ });
- mutations: {
- UPDATEUSERS(state, data){
- state.users = data;
- storage.setJson("users",data);
- },
- DELETEUSERS(state,name){
- state.users = null;
- storage.remove(name);
- },
- UPDATEPAGE(state, data){
- state.currentpage = data;
- storage.setJson("pageName",data);
- },
-
-
- },
- // Action 可以包含任意异步操作
- // 通过 context.commit 可以方问mutations方法
- // 也可以获得getters内容
- // 通过 this.$store.dispatch("getUser") 来取得内容
- actions: {
- getUser(context){
- //console.log(context.getters.cart)
- },
- usersStatus(context){
- return new Promise(function (resolve, reject) {
- let users = storage.getJson("users");
- if(users == null){
- reject();
- }else{
- resolve();
- }
- });
- },
- // usersMobile(context){
- // return new Promise(function (resolve, reject) {
- // let mobile = storage.getJson("mobile");
- // if(mobile == null){
- // reject();
- // }else{
- // resolve();
- // }
- // });
- // }
- }
- })
- export default store
|