微信小程序 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

     })

   },

}

相關文章
相關標籤/搜索