解决办法:
在自定义组件内获取必须用SelectorQuery.in()
Component({lifetimes: {ready() {const query = wx.createSelectorQuery().in(this)const num = Math.ceil(this.data.picList.length / LINE_LENGTH)query.select('.tab-content-item').boundingClientRect((rect) => {this.setData({swiperHeight: rect.height * num + 'rpx'})}).exec()}}, })
const query = wx.createSelectorQuery().in(this)
这一句是最重要的,要用.in(this),this传入的是自定义组件的实例。
否则获取到的rect值为null
https://segmentfault.com/a/1190000019548718?utm_source=tag-newest&tdsourcetag=s_pcqq_aiomsg
https://blog.csdn.net/txl910514/article/details/102584093