当获取页面某个元素 失败时,第一反应 就想想是不是 页面没加载完 就调用了,此时想到this.$nextTick()
例如如下 获取某个class的高度
onLoad() {
//console.log('globalData', getApp().globalData);
this.result = getApp().globalData.zzreport;
this.$nextTick(function(){
this.getbaseHeight();
})
},
onShow(){},
methods: {
getbaseHeight(){
let that = this;
let view = uni.createSelectorQuery().select('.b-bqhg-str');
view.boundingClientRect(function(res) {
if(res){
//获取基本信息的高度=data.height
if(res.height >= 80){
that.isbaseShow = true;
}
}
}).exec();
},
}