import Vue from 'vue'
|
import Vuex from 'vuex'
|
|
Vue.use(Vuex)
|
|
const navHeight = uni.getStorageSync('navHeight');
|
const statusbarHeight = uni.getStorageSync('statusbarHeight');
|
|
const store = new Vuex.Store({
|
|
state: {
|
navHeight: navHeight || '',
|
statusbarHeight: statusbarHeight || ''
|
},
|
mutations: {
|
// 设置导航栏高度
|
setHeight(state, val) {
|
state.navHeight = val.navHeight
|
state.statusbarHeight = val.statusbarHeight
|
uni.setStorageSync('navHeight', val.navHeight);
|
uni.setStorageSync('statusbarHeight', val.statusbarHeight);
|
}
|
},
|
|
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;
|