wepy騷操作合集

1.在自定義組件中使用wx.createSelectorQuery

const query = wx.createSelectorQuery().in(this)
query.select('#the-id').boundingClientRect(res => {
   console.log(res)
 }).exec()

預期是ready生命週期中,在子組件獲取元素高度
如果不使用in(this), 獲取的rect是null.但是使用this的話會

An SelectorQuery call is ignored because no proper page or component is found. 
Please considering using SelectorQuery.in to specify a proper one.

精華

this 拿到是是 wepy 實例, this.$wx 纔是小程序的實例

const query = wx.createSelectorQuery().in(this.$wx)
query.select('#the-id').boundingClientRect(res => {
   console.log(res)
 }).exec()

搞定
在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章