uni-app 自定義導(dǎo)航欄在微信小程序用膠囊控制位置

例如:創(chuàng)建個(gè)navigationMixin.js文件

export const systemInfo = { data: () => ({ statusBarHeight: 0, navigationBarHeight: 0, navigationBarHeight1: 0,//導(dǎo)航欄高度 navHeight: 0, jnWidth:0, jnHeight:0, jnTop: 0,//膠囊距離頂部高度 jnRight:0,//膠囊距離右側(cè)寬度 jnLeft: 0, windowHeight: 0, // 可使用窗口高度 jnBottom: 0, }), methods: { // 獲取設(shè)備信息 getSystemInfo() { // 狀態(tài)欄高度 this.statusBarHeight = uni.getSystemInfoSync().statusBarHeight // #ifdef MP-WEIXIN // 獲取微信膠囊的位置信息 width,height,top,right,left,bottom const custom = wx.getMenuButtonBoundingClientRect() // console.log(custom) // 導(dǎo)航欄高度(標(biāo)題欄高度) = 膠囊高度 + (頂部距離 - 狀態(tài)欄高度) * 2 this.navigationBarHeight1 = custom.height + (custom.top - this.statusBarHeight) * 2; // 膠囊高度 this.navigationBarHeight = custom.height; this.jnWidth = custom.width; this.jnTop = custom.top; this.jnRight = custom.right; this.jnBottom = custom.bottom, this.jnHeight = custom.height; this.jnLeft = custom.left; // 總體高度 = 狀態(tài)欄高度 + 導(dǎo)航欄高度 this.navHeight = this.navigationBarHeight + this.statusBarHeight // #endif }, }, }

頂部自定義導(dǎo)航欄使用

按需引入

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容