getMenuButtonBoundingClientRect 在后台不断报错, 有好的解决方案吗?
错误信息:
尝试过的方法:
- 在组件生命周期 __onShow __里调用
- 使用 try catch 进行兼容, 代码如下:
const getHeaderHeight = (statusBarHeight, isAndroid) => {
let rect = null;
try {
rect = wx.getMenuButtonBoundingClientRect ? wx.getMenuButtonBoundingClientRect() : null;
if (!rect) throw new Error('getMenuButtonBoundingClientRect error');
let gap = rect.top - statusBarHeight;
const navbarHeight = 2 * gap + rect.height;
const wrapHeight = navHeight + statusBarHeight;
return [wrapHeight, navHeight];
} catch(e) {
const navHeight = isAndroid ? 48 : 44;
const wrapHeight = navHeight + statusBarHeight;
return [wrapHeight, navHeight];
}
}
结果:
后台仍然在报错
请问大家有什么好的解决方案吗