taro小结-自定义navbar相关

// data中 设置全局变量

// app.js

taroGlobalData = {
    navHeight: '',
    navTop:''
  }
  componentDidMount () {
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    wx.getSystemInfo({
      success: res => {
        let statusBarHeight = res.statusBarHeight,
        navTop = menuButtonObject.top,//胶囊按钮与顶部的距离
        navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight)*2;//导航高度
        this.taroGlobalData.navHeight = navHeight;
        this.taroGlobalData.navTop = navTop;
      },
      fail(err) {
        console.log(err);
      }
    })
  }


// 在页面使用
// 实例化
const app = Taro.getApp()
// 使用app.调用
全部评论

相关推荐

头像
点赞 评论 收藏
转发
点赞 收藏 评论
分享
牛客网
牛客企业服务