小程序动态获取自定义Tabbar的高度

1、在 tabbar 组件 js文件的 ready 方法中加入以下代码

 ready() {
    const query = wx.createSelectorQuery().in(this)
    query.select('.tab-bar').boundingClientRect((rect) => {
      // 缓存tabbar栏的高度
      wx.setStorageSync('tabbarHeight', rect.height)
    }).exec()
 }

2、需要使用的时候

 wx.getStorageSync('tabbarHeight')
posted @ 2023-01-10 11:44  Rins  阅读(1622)  评论(0编辑  收藏  举报