微信小程序createSelectorQuery获取偶尔为null

异步渲染了,加了个定时器,不合理但好用

 onReady(){
  let that=this
  setTimeout(function(){
    //获取左上方的高度
    wx.createSelectorQuery().in(that).selectAll('#textHeight').boundingClientRect((react)=> {
      if(react[0]!==null){
        that.setData({
          textOpen:react[0].height > 100 ? true : false
        })
      }
    }).exec()
    },500)
  },

猜你喜欢

转载自blog.csdn.net/weixin_51263829/article/details/129703328