uniapp-兼容H5和微信小程序, 自定義導航欄
- 動態的樣式無法編譯到微信小程序。
- 動態傳過來的函數無法編譯到微信小程序。
UNIAPP自定義導航欄適配問題和微信小程序齊劉海適配問題
代碼:
// #ifdef MP-WEIXIN
let systemInfo = uni.getSystemInfoSync()
// 獲取頭部狀態欄> 就是顯示電量的那部分。因為有個齊劉海的問題要處理
this.statusBarHeight = systemInfo.statusBarHeight
// 獲取微信小程序右上角膠囊按鈕的API
let menuButtonInfo = uni.getMenuButtonBoundingClientRect()
// 膠囊按鈕距離最上方的高度 - 狀態條的高度 * 2 + 膠囊按鈕的高度 + 狀態條的高度
this.statusBarHeight = (menuButtonInfo.top - this.statusBarHeight) + menuButtonInfo.height + systemInfo.statusBarHeight
// #endif
詳解圖: