wx.createSelectorQuery().in(that).selectAll('.tag-box-wrap').boundingClientRect(function (rect) {
that.setData({
tagHeight3: rect[0] &&rect[0].height ,
})
}).exec()
*不添加 .in(that) rect[0].height返回的永远是null
重点:将选择器的选取范围更改为自定义组件 component 内。(初始时,选择器仅选取页面范围的节点,不会选取任何自定义组件中的节点)*
Component({
queryMultipleNodes (){
const query = wx.createSelectorQuery().in(this)
query.select('#the-id').boundingClientRect(function(res){
res.top // 这个组件内 #the-id 节点的上边界坐标
}).exec()
}
})
参考地址:https://developers.weixin.qq.com/miniprogram/dev/api/wxml/SelectorQuery.in.html
微信小程序组件中(获取元素节点信息)
最新推荐文章于 2024-04-06 22:16:42 发布