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
| import Vue from 'vue'
| import Vuex from 'vuex'
|
| Vue.use(Vuex)
| const userInfo = uni.getStorageSync('userInfo');
|
| const store = new Vuex.Store({
|
| state: {
| userInfo: userInfo || null // 用户信息
| },
| mutations: {
| // 设置用户信息
| setUserInfo(state, val) {
| state.userInfo = val
| uni.setStorageSync('userInfo', val);
| }
| },
|
| actions: {
| // 获取状态高度
| getHeight(context) {
| let res = uni.getMenuButtonBoundingClientRect()
| let status = uni.getSystemInfoSync()
| var height = res.height
| let statusbarHeight = status.statusBarHeight
| let navHeight = res.height + (res.top - statusbarHeight) * 2;
| context.commit('setHeight', { statusbarHeight, navHeight, height })
| }
| }
|
| })
|
| export default store;
|
|