收藏
回答

getMenuButtonBoundingClientRect偶尔获取不到值

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug getMenuButtonBoundingClientRect 客户端 7.0.4 最近版本

在真机和在开发工具上,经常这个值获取不到

回答关注问题邀请回答
收藏

10 个回答

  • 小程序技术专员-binnie
    小程序技术专员-binnie
    2019-09-17

    感谢反馈,后续会修复。 目前可以加延迟 100ms 或者 发现拿到异常值再重新获取

    2019-09-17
    有用 2
    回复 11
    • 木槿子
      木槿子
      2019-09-20
      测试,有效的
      2019-09-20
      回复
    • 小程序技术专员-binnie
      小程序技术专员-binnie
      2019-09-20回复木槿子
      ios7.0.7修复了,准确的值最好在onWindowResize之后获取
      2019-09-20
      1
      回复
    • 何涛
      何涛
      2019-09-26
      7.0.7是修复了没有报错了
      2019-09-26
      回复
    • 绿茶
      绿茶
      2019-10-14
      加延迟是指在哪里加
      2019-10-14
      回复
    • 小程序技术专员-binnie
      小程序技术专员-binnie
      2019-10-14回复绿茶
      建议的是onShow里面调用
      2019-10-14
      回复
    查看更多(6)
  • 禾店短剧系统
    禾店短剧系统
    2021-05-26

    还好是有社区,不然这个些问题怎么办啊

    2021-05-26
    有用 1
    回复 1
    • 🧸
      🧸
      2021-06-07
      QQ小程序更tm的惨,什么问题都有,什么问题都找不到答案
      2021-06-07
      回复
  • Leon
    Leon
    2021-10-29
    //2021-11-29 又踩了一次坑,写了个超强补丁,有再遇到回复下
    
    onLaunch: function (options) {
    
    const getGlobalData = () => {
    
    const systemRes = wx.getSystemInfoSync()
    
    this.globalData.statusBarHeight = systemRes.statusBarHeight;
    
    this.globalData.boundingRect = wx.getMenuButtonBoundingClientRect();
    
    if (!this.globalData.boundingRect || this.globalData.boundingRect.height <= 0 && this.globalData.statusBarHeight <= 0 && wx.onWindowResize) {
    
    wx.onWindowResize(() => {
    
    getGlobalData()
    
    })
    
    }
    
    }
    
    getGlobalData();
    
    }
    
    
    
    //组件内
    
    attached: function () {
    
    // 定义导航栏的高度
    
    const setHeight = (boundingRect, statusBarHeight) => {
    
    if (boundingRect && boundingRect.height > 0 && statusBarHeight > 0) {
    
    this.setData({
    
    height: statusBarHeight,
    
    boundingRect: boundingRect
    
    })
    
    this.triggerEvent('fetchHeight', {
    
    height: boundingRect.height + boundingRect.top * 2 - statusBarHeight
    
    })
    
    } else {
    
    setTimeout(() => {
    
    const systemRes = wx.getSystemInfoSync()
    
    const statusBarHeight = systemRes.statusBarHeight;
    
    const boundingRect = wx.getMenuButtonBoundingClientRect();
    
    setHeight(statusBarHeight, boundingRect)
    
    }, 1000)
    
    }
    
    }
    
    setHeight(app.globalData.boundingRect, app.globalData.statusBarHeight)
    
    }
    
    
    
    2021-10-29
    有用
    回复
  • 胡秋云
    胡秋云
    2019-12-07

    这玩意什么时间能修复好,偶尔获取不到呀。

    2019-12-07
    有用
    回复
  • 2019-09-16

    请问你这个问题官方解决了吗,我在app.js onLaunch使用wx.getMenuButtonBoundingClientRect();方法它的top,right,bottom,left偶尔都为空,我可以重现,机型ios,安卓目前还不清楚


    2019-09-16
    有用
    回复
  • puma
    puma
    2019-09-05

    开发工具v1.02.1808100

    let menuButtonObject = wx.getMenuButtonBoundingClientRect();

    console.log(menuButtonObject.height)

    返回undefined

    2019-09-05
    有用
    回复
  • 蕉太.🍭
    蕉太.🍭
    2019-08-18

    我在荣耀V20发现了这个问题

    2019-08-18
    有用
    回复
  • 海风-海外新生活
    海风-海外新生活
    2019-06-06

    iphoneX 类的手机都会有这个问题,有时能获取,有时不能获取。 和微信版本号没有关联:

    Appid: wxcd437f6ab838ebf7

    昵称: 海外新生活

    时间: 2019-06-06 03:42:54

    次数: 5分钟 1次

    类型:脚本错误

    错误样例: getMenuButtonBoundingClientRect:fail:access denied; at wx.getMenuButtonBoundingClientRect

    登录公众平台小程序运维中心可查看更多错误信息


    2019-06-06
    有用
    回复 1
    • 海风-海外新生活
      海风-海外新生活
      2019-06-06

      iphone6, android和开发工具上没有这样的问题。

      2019-06-06
      回复
  • 镜言
    镜言
    2019-05-28

    我也发现了,iphone有时候会获取不到值,但是android一直很稳定。我在 app.js 的onLaunch 和 onShow 里面都试过调用 getMenuButtonBoundingClientRect 方法, 获取的 bottom 和 top 都是0,其他值没进行输出,不知道是否有值

    2019-05-28
    有用
    回复 3
    • 2019-05-28

      仅仅是iphone偶尔会出现这个问题,我现在解决方案就是增加一个默认值,虽然页面会有一点不同,但是可以保持页面不崩,我之前看到有人说在全局里面获取这个内容,但是经过几十次的测验之后,仍然出现这个问题,这个东西还是不能这样直接做。希望官方能尽快解决

      2019-05-28
      回复
    • 镜言
      镜言
      2019-05-28回复

      我就是在全局里面调的,哈哈哈,偶尔有问题。实在不行我给个默认值

      2019-05-28
      回复
    • The-fighter-
      The-fighter-
      2019-10-12回复镜言
      每个机型不一样,默认值给多少合适呢
      2019-10-12
      回复
  • 灵芝
    灵芝
    2019-05-27

    获取不到具体是什么表现呢?麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2019-05-27
    有用
    回复 25
    • 2019-05-27

      也就一个API,在真机上有的时候,获取到值为0

      2019-05-27
      回复
    • 灵芝
      灵芝
      2019-05-27回复

      是所有数值都是0么?具体的机型、微信版本号是什么?

      2019-05-27
      回复
    • 2019-05-27回复灵芝

      只有top和height为0,iphonexsmax 微信版本号是最新的,我已经因为这个问题,被我老板叼了两次了

      2019-05-27
      回复
    • 灵芝
      灵芝
      2019-06-18回复

      现在再试试,还有这个问题么?

      2019-06-18
      回复
    • 2019-09-16回复灵芝
      我可以给你重现
      2019-09-16
      回复
    查看更多(20)
登录 后发表内容