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