如何解决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,为什么还说我组件不明确?
我看官方文档也是这样写的呀
希望能得到解答,康萨迷大!