feat:first commit
This commit is contained in:
34
src/store/index.ts
Normal file
34
src/store/index.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import Vuex from 'vuex'
|
||||
import Vue from 'vue'
|
||||
Vue.use(Vuex)
|
||||
import UserStore from './modules/user'
|
||||
|
||||
const store = new Vuex.Store({
|
||||
state: {
|
||||
// 在此定义状态
|
||||
navHeight: 0
|
||||
},
|
||||
getters: {
|
||||
// 在此定义 getter 函数
|
||||
getNavHeight(state: any) {
|
||||
return state.navHeight
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
// 在此定义 mutation 函数
|
||||
setNavHeight(state: any, height: number) {
|
||||
state.navHeight = height
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
// 在此定义 action 函数
|
||||
SetNavHeight({ commit }: any, height: number) {
|
||||
commit('setNavHeight', height)
|
||||
}
|
||||
},
|
||||
modules: {
|
||||
UserStore,
|
||||
}
|
||||
})
|
||||
|
||||
export default store
|
||||
29
src/store/modules/user.js
Normal file
29
src/store/modules/user.js
Normal file
@@ -0,0 +1,29 @@
|
||||
import { getUserInfo, setUserInfo } from '@/utils/util'
|
||||
|
||||
const prevUserInfo = getUserInfo()
|
||||
export default {
|
||||
namespaced: true,
|
||||
state: {
|
||||
userInfo: prevUserInfo || {},
|
||||
registerInfo: {},
|
||||
isLogin: !!prevUserInfo
|
||||
},
|
||||
getters: {
|
||||
// 在此定义 getter 函数
|
||||
getUserInfo(state) {
|
||||
return state.userInfo
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
changeUserInfo(state, data) {
|
||||
state.userInfo = data
|
||||
state.isLogin = !!data
|
||||
setUserInfo(state.userInfo)
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
setUserInfo({ commit }, data) {
|
||||
commit('changeUserInfo', data)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user