Error content
Uncaught TypeError: Cannot read property 'bottom' of null
at a (chunk-vendors.js:319)
at chunk-vendors.js:319
at Array.forEach (<anonymous>)
at IntersectionObserver.s.<computed>.IntersectionObserver.root (chunk-vendors.js:319)
Cause
the listening element cannot be found
PS: it seems that it only appears from the H5 platform
Solution
in the hide and unload life cycle of the page, cancel listening to elements
onHide:function(){
this.observer.disconnect();
},
onUnload: function(){
this.observer.disconnect();
},
Judge whether the element exists during listening, and clear the last listening
Vue.prototype.$lazyImg = function(fn){
this.observer.disconnect();//The previous ones must be cleared. Otherwise, elements that have been loaded will still be listened to, or if the listened to elements disappear, an error will be reported
uni.createSelectorQuery().in(this).selectAll('.lazy').boundingClientRect(data => {
if(data.length > 0){//If there is no lazy element on the page, it will report an error directly, which is really fucking outrageous!
this.observer.observe('.lazy', (res) => {
if(res.intersectionRatio > 0){//sometimes, intersectionRatio is undefined
fn(res.dataset)
}
})
}
}).exec();
}
Read More:
- JS bug Log Uncaught TypeError: Cannot read property ‘previoustSibling‘ of null
- [Solved] electron Error: Uncaught TypeError: Cannot read property ‘BrowserWindow‘ of undefined
- Method to solve uncaught typeerror: cannot set property ‘onclick’ of null error
- [Solved] Error in callback for watcher “value“: “TypeError: Cannot read property ‘level‘ of null“
- [Solved] JS Error: Uncaught TypeError: Cannot set properties of null (setting ‘innerHTML‘)
- [Solved] Echarts Error: TypeError: Cannot read properties of null (reading getAttribute )
- [Solved] Vue Error: TypeError: Cannot read property ‘end‘ of undefined
- Uni-app Error when assigning a value to a component: [system] TypeError: Cannot read property ‘name‘ of undefined
- [Solved] TYPEERROR: CANNOT READ PROPERTY ‘REDUCE‘ OF UNDEFINED
- [Solved] Vue3 Import element UI error: Uncaught TypeError: Cannot read properties of underfined…
- [Solved] react Chrome Browser Error: Uncaught TypeError: Cannot read properties of undefined (reading ‘forEach‘)
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- [Solved] Syntax Error: TypeError: Cannot read property ‘parseComponent‘ of undefined
- [Solved] Install The Latest Version of Jest Error: TypeError: Cannot read property ‘instrument‘ of undefined
- Echarts Partially introduced error: TypeError: Cannot read property ‘findAxisModel’ of undefined
- [Solved] vue.esm.js?efeb:591 [Vue warn]: Error in event handler for “click“: “TypeError: Cannot read property
- uniapp Use render Function Error: [Vue warn]: Error in beforeCreate hook: “TypeError: Cannot read property ‘_i‘ of
- [Solved] uni app TypeError: undefined is not an object (evaluating ‘modules[moduleId].call‘) __ERROR
- [Solved] NPM err! Cannot read property ‘parent’ of null npm ERR! A complete log of this run can be found in: npm ERR!
- vue Error: Uncaught SyntaxError: Invalid shorthand property initializer