收藏
回答

createSelectorQuery 页面初始化拿不到节点信息如何解决?

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 需求 wx.createSelectorQuery() 工具 6.5.3 2.2.5

每次小程序重新打开 都会报错

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


提示我页面或者组件找不到 ,导致wx.createSelectorQuery() 节点信息也没有,然后刷新一下就好了,这个请问大神们怎么解决啊?

方法写在onScrollHandle

onScrollHandle(e) {
if (this.sectionNavNodeRefs.length === 0) this.getSectionNodeRefs()

搜的是首页滚动内容的节点信息

getSectionNodeRefs() {
this.sections.forEach((item, index) => {
wx.createSelectorQuery().select(`#${item.name}`).boundingClientRect((res) => {
if (res) {
item.nodeRefs = res
this.sectionTops.push(res.top)
}
}).exec()

wx.createSelectorQuery().select(`#nav${item.name}`).boundingClientRect((res) => {
if (res) {
console.log(res)
this.sectionNavNodeRefs.push(res)
}
}).exec()

})

BTW :SelectorQuery.in(this)没用,用的MPVUE,

程序是除了第一次打开工具的时候才会报错,之后刷新都是可以运行的,应该是API的问题,如何解决?

最后一次编辑于  2018-09-03
回答关注问题邀请回答
收藏

5 个回答

  • LastLeaf
    LastLeaf
    2018-09-26

    你好,这是目前开发者工具上的一个已知 bug ,只在刚启动开发者工具窗口时出现。我们之后会修复。

    2018-09-26
    有用 1
    回复
  • GJ
    GJ
    2019-04-11

    我今天也遇到这个问题,最后做了个执行函数,直到能获取到数据


    2019-04-11
    有用 2
    回复
  • 灵芝
    灵芝
    2018-09-03

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

    2018-09-03
    有用
    回复 1
    • undefined
      undefined
      2018-09-05

      我也遇到开发工具selectQuery在重启时抛出warning不执行exec的问题,刷新后才正常的问题,并且在真机上重启时也会偶发。   wechatide://minicode/QsGPOcm4712y

      2018-09-05
      回复
  • 再见,电脑崽
    再见,电脑崽
    2018-09-03

    请在wxml加载结束后再执行wx.createSelectorQuery(),一般会写到onReady里。

    2018-09-03
    有用
    回复 6
    • JNL
      JNL
      2018-09-03

      onReady拿不到 我才写到onScrollHandle 待用户交互以后再获取

      2018-09-03
      回复
    • 再见,电脑崽
      再见,电脑崽
      2018-09-03回复JNL

      多贴点代码吧。看不出所以然。

      2018-09-03
      回复
    • 再见,电脑崽
      再见,电脑崽
      2018-09-03回复JNL

      换下基础库到2.0.9及之前版本试试看

      2018-09-03
      回复
    • JNL
      JNL
      2018-09-03回复再见,电脑崽

      嗯 ,可以了,啥原因啊

      2018-09-03
      回复
    • 再见,电脑崽
      再见,电脑崽
      2018-09-03回复JNL

      2.1.0及后的BUG吧,等官方修复。

      2018-09-03
      回复
    查看更多(1)
  • 卢霄霄
    卢霄霄
    2018-09-03

    截图看看你这个方法写到哪里的,还有,你要搜的是啥

    2018-09-03
    有用
    回复 10
    • JNL
      JNL
      2018-09-03

      写在onScrollHandle

      onScrollHandle(e) {
      if (this.sectionNavNodeRefs.length === 0) this.getSectionNodeRefs()

      搜的是首页滚动内容的节点信息

      2018-09-03
      回复
    • 卢霄霄
      卢霄霄
      2018-09-03回复JNL

      能做个代码片段吗?你描述的和截图。。什么都看不出来

      https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

      2018-09-03
      回复
    • JNL
      JNL
      2018-09-03回复卢霄霄

      就是初始化程序的时候,不管在哪写方法,搜的哪个节点,wx.createSelectorQuery().select(id)都拿不到节点信息,刷新以后可以

      getSectionNodeRefs() {
      this.sections.forEach((item, index) => {
      wx.createSelectorQuery().select(`#${item.name}`).boundingClientRect((res) => {
      if (res) {
      item.nodeRefs = res
      this.sectionTops.push(res.top)
      }
      }).exec()

      wx.createSelectorQuery().select(`#nav${item.name}`).boundingClientRect((res) => {
      if (res) {
      console.log(res)
      this.sectionNavNodeRefs.push(res)
      }
      }).exec()

      })

      这是拿节点的方法

      2018-09-03
      回复
    • 卢霄霄
      卢霄霄
      2018-09-03回复JNL

      没遇到过,也看不出问题。。搜了下,好像都还没解决

      https://developers.weixin.qq.com/community/search?query=An%20SelectorQuery%20call&page=1

      2018-09-03
      回复
    • JNL
      JNL
      2018-09-03回复卢霄霄

      嗯,好想是的,等官方修复吧

      2018-09-03
      回复
    查看更多(5)
登录 后发表内容