SelectorQuery首次进入开发者工具的时候会报错
发布于 6 年前 作者 leiqiu 11214 次浏览 来自 问答

我需要在组件就绪的时候知道它的宽高,如下在ready函数内做的:

Component({
  ready: function ready() {
    // TODO: 首次打开开发者工具弹出警告:
    //       VM54:1 An SelectorQuery call is ignored because no proper page or component is found.
    var query = this.createSelectorQuery();
    query.select('#foo').boundingClientRect();
    query.exec(function (_ref) {
      var component = _ref[0];
 
      console.log('component', component);
    });
  }
});

但这一步会在第一次打开开发者工具的时候报错:

VM54:1 An SelectorQuery call is ignored because no proper page or component is found. Please considering using `SelectorQuery.in` to specify a proper one.

会发现query.exec根本没有执行。这只在第一次打开开发者工具的时候才会发生,后续的编译不会出现这个问题了。我现在担心的是在真机上是否也会这样?希望官方能够尽快解决这个漏洞。

3 回复

你好,这是一个已知问题,我们会尽快进行修复。另外建议后续经过搜索后再提问,以提高问题解答的效率。

在页面里面用wx.createSelectorQuery()获取组件里面的dom,返回结果是null,已经设置了定时器,是小程序不支持这个操作么?还是其他什么原因呢?

嗯,我也是。。我在真机上还没遇到,不过有的人据说是遇到了

回到顶部