import { createStore } from 'vuex' const store = createStore({ state: { userInfo: uni.getStorageSync("SY_USER") || null, farm: JSON.parse(uni.getStorageSync("farm") || "{}"), house: JSON.parse(uni.getStorageSync("house") || "{}"), tabbrIndex: 0, }, mutations: { saveUserInfo(state, info) { state.userInfo = info uni.setStorageSync("SY_USER", info) }, setFarm(state, data) { state.farm = data; uni.setStorageSync('farm', JSON.stringify(data)); }, setHouse(state, data) { state.house = data; uni.setStorageSync('house', JSON.stringify(data)); }, changeTabbar(state, index) { state.tabbrIndex = +index }, }, actions: { saveUserInfo({ commit }, info) { commit('saveUserInfo', info); }, setFarm({ commit }, info) { commit('setFarm', info) }, setHouse({ commit }, info) { commit('setHouse', info) }, changeTabbar({ commit }, info) { commit('changeTabbar', info) }, } }) export default store