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


<div class="ex" id="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

     })

   },

}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM