初始化
This commit is contained in:
48
common/store/index.js
Normal file
48
common/store/index.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import Vue from 'vue'
|
||||
import Vuex from 'vuex'
|
||||
Vue.use(Vuex)
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
hasLogin: false,
|
||||
token: '',
|
||||
userInfo: {},
|
||||
},
|
||||
getters: {
|
||||
hasLogin(state){
|
||||
if(uni.getStorageSync('hasLogin')) state.hasLogin = uni.getStorageSync('hasLogin')
|
||||
return state.hasLogin;
|
||||
},
|
||||
token: function(state){
|
||||
if(uni.getStorageSync('token')) state.posterImage = uni.getStorageSync('token')
|
||||
return state.token;
|
||||
},
|
||||
userInfo: (state) => {
|
||||
if(uni.getStorageSync('userInfo')) state.userInfo = uni.getStorageSync('userInfo')
|
||||
return state.userInfo
|
||||
},
|
||||
},
|
||||
mutations: {
|
||||
set: (state, objs)=>{
|
||||
var key = Object.keys(objs)[0]
|
||||
state[key] = objs[key]
|
||||
uni.setStorageSync(key,objs[key])
|
||||
},
|
||||
get: (state, key)=>{
|
||||
if(uni.getStorageSync(key)) state[key] = uni.getStorageSync(key)
|
||||
return state[key];
|
||||
},
|
||||
login: (state, accesstoken)=>{
|
||||
state.hasLogin = true
|
||||
state.token = accesstoken
|
||||
uni.setStorageSync('hasLogin', true)
|
||||
uni.setStorageSync('token', accesstoken)
|
||||
},
|
||||
logout: (state)=>{
|
||||
state.hasLogin = false
|
||||
state.token = ''
|
||||
state.userInfo = {}
|
||||
uni.clearStorageSync()
|
||||
}
|
||||
}
|
||||
})
|
||||
export default store
|
Reference in New Issue
Block a user