收藏
回答

如何解决createSelectorQuery无法获取不到节点?

 
          console.log(this)
          const query = wx.createSelectorQuery().in(this)
          query.select('.pp-navbar__item').boundingClientRect(function (rect) {
            // this.sliderOffset = rect[1].width;
            // this.setData({
            //     sliderOffset:rect[1].width
            // });
            console.log(this)
            console.log(rect[0].width)
          }).exec()


需求:想要获取节点的宽度,并传入data中,保存起来

报错


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


我明明打印的出this,为什么还说我组件不明确?

我看官方文档也是这样写的呀


希望能得到解答,康萨迷大!



回答关注问题邀请回答
收藏

4 个回答

  • 张春亚
    张春亚
    2021-02-07

    不用.in(this)

    let query = wx.createSelectorQuery()

    获取成功

    2021-02-07
    有用 3
    回复
  • Sam
    Sam
    2021-12-10

    我想问下解决了吗?放在onShow还是onReady?有用到定时吗?

    2021-12-10
    有用
    回复
  • 复杂人生
    复杂人生
    2020-06-19

    你好请问解决了吗?我现在也遇到了

    2020-06-19
    有用
    回复
  • 是小白啊
    是小白啊
    2019-10-17

    修改下,可先看下文档https://developers.weixin.qq.com/miniprogram/dev/api/wxml/wx.createSelectorQuery.html

    2019-10-17
    有用
    回复 5
    • X_wing
      X_wing
      2019-10-17
      我改成了query = this.createSelectorQuery();但是直接报错VM3099:1 thirdScriptError
      _this2.createSelectorQuery is not a function;at pages/tabBar/login onShow function;at api getSetting success callback function
      TypeError: _this2.createSelectorQuery is not a function
      2019-10-17
      回复
    • 是小白啊
      是小白啊
      2019-10-17回复X_wing
      麻烦提供能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
      2019-10-17
      回复
    • 2019-11-21
      请问解决了吗?遇到相同问题
      2019-11-21
      回复
    • 2020-03-10
      你这个坑真是不浅啊
      2020-03-10
      回复
    • 皱凯凯凯凯
      皱凯凯凯凯
      2021-01-11
      修复了吗??
      2021-01-11
      回复
登录 后发表内容
问题标签