fix(merch/detail): 防止重复初始化头部高度
1. 新增headerHeightInited状态避免重复调用initHeaderHeight 2. 在initHeaderHeight中增加商品名称校验防止无效执行 3. 仅在页面首次获取商品数据后初始化头部高度
This commit is contained in:
@@ -322,7 +322,8 @@ export default {
|
||||
return {
|
||||
headerHeight: 320,
|
||||
screenWidth: uni.getSystemInfoSync().windowWidth,
|
||||
changeStyleDebounce: null
|
||||
changeStyleDebounce: null,
|
||||
headerHeightInited: false
|
||||
};
|
||||
},
|
||||
mixins: [list],
|
||||
@@ -337,7 +338,9 @@ export default {
|
||||
if (res.code >= 0 && res.data) {
|
||||
this.merch = res.data;
|
||||
this.$nextTick(() => {
|
||||
if (!this.headerHeightInited) {
|
||||
this.initHeaderHeight();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -353,10 +356,13 @@ export default {
|
||||
}
|
||||
},
|
||||
initHeaderHeight() {
|
||||
if (!this.merch || !this.merch.merch_name) return;
|
||||
if (this.headerHeightInited) return;
|
||||
const query = uni.createSelectorQuery().in(this);
|
||||
query.select('.head-wrap').boundingClientRect(rect => {
|
||||
if (rect && rect.height > 0) {
|
||||
this.headerHeight = (rect.height / this.screenWidth) * 750;
|
||||
this.headerHeightInited = true;
|
||||
}
|
||||
}).exec();
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user