Uncaught TypeError: Cannot read property 'bottom' of null
at a (chunk-vendors.js:1973)
at chunk-vendors.js:1973
at Array.forEach (<anonymous>)
at IntersectionObserver.s.<computed>.IntersectionObserver.root (chunk-vendors.js:1973)
用空页面也会报此错误
Uncaught TypeError: Cannot read property 'bottom' of null
at a (chunk-vendors.js:1973)
at chunk-vendors.js:1973
at Array.forEach (<anonymous>)
at IntersectionObserver.s.<computed>.IntersectionObserver.root (chunk-vendors.js:1973)
用空页面也会报此错误
sticky组件创建了Observer监听,当切换页面且页面没有销毁(例如:tabbar页面), sticky组件也没有销毁,自然beforeDestroy没有生效,导致组件仍然保持监听,所以出现Cannot read property 'bottom' of null报错。所以我们需要手动断开监听来解决这个报错
<template>
<view>
<!-- @property {Boolean} enable 是否开启吸顶功能(默认true)-->
<u-sticky :enable="enable" h5-nav-height="0">
<view>
……
</view>
</u-sticky>
</view>
</template>
<script>
export default {
data() {
return {
// 是否开启吸顶功能
enable: true
}
},
// 在对应的show和hide页面生命周期中打开或关闭监听
onShow() {
this.enable= true
},
onHide() {
//页面销毁时,取消监听
this.enable= false
}
}
</script>
shsszhao
是吸顶导致的报错,正解
2021-11-16 10:48