事件lockBtnTap()执行,wx.createSelectorQuery()计算元素节点宽度这段代码有时候执行到,有时候没执行到;看打印的log,执行的时候打印出来是这样,不执行的时候是
(我给它断点的时候才100%执行到,去掉断点就执行不到了)
lockBtnTap(event){ this .setData({ lockDialogBoll: true , curLockName: event.currentTarget.dataset.name }); console.log( 'laiba' ) //计算弹窗滑动开门盒子 var _this = this ; wx.createSelectorQuery().selectAll( '.slideBox' ).boundingClientRect( function (rects) { rects.forEach( function (rect) { // rect.id // 节点的ID // rect.dataset // 节点的dataset // rect.left // 节点的左边界坐标 // rect.right // 节点的右边界坐标 // rect.top // 节点的上边界坐标 // rect.bottom // 节点的下边界坐标 // rect.width // 节点的宽度 // rect.height // 节点的高度 _this.setData({ slideBoxWidth: rect.width }) console.log( 'slideBoxWidth:' +rect.width); }) }).exec() wx.createSelectorQuery().selectAll( '.slide' ).boundingClientRect( function (rects) { rects.forEach( function (rect) { _this.setData({ slideWidth: rect.width }) console.log( 'slideWidth:' + rect.width); }) }).exec() } |
如果认为有bug,麻烦给个相关的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html),我们定位下问题。
1.5.0版本开始,详见:
https://mp.weixin.qq.com/debug/wxadoc/dev/framework/app-service/page.html
你好,你在setData之后直接调用createSelectorQuery,目前可能会有问题(因为目前setData是个异步调用)。你可以在setData的callback中使用createSelectorQuery。
之后我们会考虑优化这个点。
我在onload的生命周期中获取接口数据,setData之后在回调中
let query = wx.createSelectorQuery()
query.select('#spOne').boundingClientRect()
query.exec(function (res) {
let h = res[0].height
这里res一直都是null(偶尔不是null) 感觉是小程序的bug,求官方给出解决办法
应该是这样吧: this.setData({
},function(){
//回调函数 })
你好,请教下setData有提供回调功能了吗?搜不到哈,那个版本开始提供的,应该怎么写回调的
rects返回偶尔为空: