在自定義組件中,獲取元素的寬高等信息時(shí),在自定義組件內(nèi)獲取必須用SelectorQuery.in(this),如下
lifetimes: {
ready() {
const query = wx.createSelectorQuery().in(this) // 要使用in(this),不然下面的res為空
const num = Math.ceil(this.data.picList.length / LINE_LENGTH)
query.select('.tab-content-item').boundingClientRect((res) => {
this.setData({
swiperHeight: res.height * num + 'rpx'
})
}).exec()
}
}