微信小程序自定义组件中获取DOM宽高

大祥子
2021-10-30 / 0 评论 / 552 阅读 / 正在检测是否收录...
温馨提示:
本文最后更新于2022年06月08日,已超过688天没有更新,若内容或图片失效,请留言反馈。

const query = wx.createSelectorQuery().in(this)
query.select('.test').boundingClientRect((rect) => {
  console.log(rect)
}).exec()
const query = wx.createSelectorQuery().in(this) // 这一句是最重要的,要用.in(this),this传入的是自定义组件的实例。否则获取到的rect值为null

const query = wx.createSelectorQuery();
const that = this;
//选择id
query.select(id).boundingClientRect(function (rect) {
  console.log(rect);// 这里包含内容 的宽高
})exec();
80

评论 (0)

取消