在工具函數(shù)utils里面新建函數(shù):
getWXStatusHeight() {
// 獲取距上
const barTop = uni.getSystemInfoSync().statusBarHeight;
// #ifdef MP
// 獲取膠囊按鈕位置信息
const menuButtonInfo = wx.getMenuButtonBoundingClientRect() || 0
// 獲取導(dǎo)航欄高度
const barHeight = menuButtonInfo.height + (menuButtonInfo.top - barTop) * 2
let barWidth = menuButtonInfo.width
// #endif
// #ifndef MP
// 獲取導(dǎo)航欄高度
const barHeight = parseInt(barTop) + 10;
let barWidth = '100%'
// #endif
return {
barHeight,
barTop,
barWidth
}
},
在main.js里面經(jīng)行掛載;
import util from 'utils/util'
Vue.prototype.$util = util;
就可以實(shí)現(xiàn)全局引用;
引用方法:
this.$util.getWXStatusHeight()