获取的早了,确保渲染完毕后再获取
如果只获取默认的节点用onReady获取即可,变量控制的用methods里面的函数,还不行就在函数里面写this.nextTick()或用延迟setTimeout
onReady() {
const self = this
let q = uni.createSelectorQuery()
//获取购物车位置
setTimeout(function () {
q.select('#cart').boundingClientRect(data => {
self.cartBasketRect = data
}).exec();
}, 100)
},
用-margin和widthFix需要用setTimeout延迟
参考:https://developers.weixin.qq.com/community/develop/doc/00082a45ef8bf832f329c632f5d800
https://developers.weixin.qq.com/community/develop/doc/0008cc408a41d88d114806a1f56c00