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

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

mounted: function (){

  //页面中直接调用

  this.getElementHeight('#ex')

  //组件中调用,我也不知道为什么要重新定义this

  let _this = this

  setTimeout(function(){

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

  }, 100) })

}

methods: {

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

  getElementHeight(id = "") {

     let _query = wx.createSelectorQuery();

    _query.select(id).boundingClientRect()

    _query.exec((res) =>{

      this.tHeight = res[0].height

     })

   },

}