不用.in(this) let query = wx.createSelectorQuery() 获取成功
如何解决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,为什么还说我组件不明确? 我看官方文档也是这样写的呀 [图片] 希望能得到解答,康萨迷大!
2021-02-07