为什么在组件中用createSelectorQuery 获取不到元素信息
发布于 6 年前 作者 guiyingwei 16762 次浏览 来自 问答

在引用得组件中

wx.createSelectorQuery().select(#id).boundingClientRect(function (rect) {

console.log(rect)

}).exec()



// 打印值为null

3 回复

你好,请具体描述问题出现的流程,并提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。

    var query = wx.createSelectorQuery().in(this)
    query.select('#the-id').boundingClientRect(function(res){
      res.top // 这个组件内 #the-id 节点的上边界坐标
    }).exec()

页面中调用组件中的dom呢?

回到顶部