微信小程序 mpvue 获取元素的高度

<div class="ex" id="ex">三行的高度,三行的高度,三行的高度,三行的高度,三行的高度,三行的高度,三行的高度</div>this

mounted: function (){get

  //页面中直接调用it

  this.getElementHeight('#ex')io

  //组件中调用,我也不知道为何要从新定义thisfunction

  let _this = thisclass

  setTimeout(function(){select

    _this.getElementHeight('#tit'+_this.index)im

  }, 100) })di

}query

methods: {

  // 获取指定元素实际宽度

  getElementHeight(id = "") {

     let _query = wx.createSelectorQuery();

    _query.select(id).boundingClientRect()

    _query.exec((res) =>{

      this.tHeight = res[0].height

     })

   },

}

相关文章
相关标签/搜索