index.js
1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store=new Vuex.Store({
state:{
attrVal:[],//detailAttr里的valindex [0,0]
attrTxt:'请选择商品规格尺寸',
keyword:'',
isLogin:0,
userinfo:uni.getStorageSync('userinfo')?JSON.parse(uni.getStorageSync('userinfo')):{}
},
mutations:{
setKeyword(state,data){
state.keyword=data.keyword
},
defaultKeyword(state){
state.keyword=''
},
setAttr(state,data){
state.attrVal=data.attrVal
state.attrTxt=data.attrTxt
},
defaultAttr(state){
state.attrVal=[]
state.attrTxt='请选择商品规格尺寸'
},
login(state,data){
state.isLogin=1;
state.userinfo=data;
uni.setStorageSync('userinfo',JSON.stringify(data))
},
logout(state){
state.isLogin=0;
state.userinfo=[
];
console.log(state.userinfo)
uni.setStorageSync('userinfo','')
uni.setStorageSync('token','')
},
setHead(state,data){
state.userinfo.image=data;
uni.setStorageSync('userinfo',JSON.stringify(state))
},
setNickname(state,data){
state.userinfo.nickname=data;
uni.setStorageSync('userinfo',JSON.stringify(state))
}
}
})
export default store;