Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/478.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在NUXTjs中跳转到其他页面时解除事件绑定?_Javascript_Vue.js_Nuxt.js - Fatal编程技术网

Javascript 如何在NUXTjs中跳转到其他页面时解除事件绑定?

Javascript 如何在NUXTjs中跳转到其他页面时解除事件绑定?,javascript,vue.js,nuxt.js,Javascript,Vue.js,Nuxt.js,我已经在一页纸上写了这段代码。它可以工作,但当我跳转到其他页面时,如何解除此事件的绑定 private-mounted(){ if(process.browser){ const banner:any=document.querySelector(“.banner img”) document.addEventListener('scroll',()=>{ const offsetTop=window.scrollY const INTOR_HEIGHT=document.querySelect

我已经在一页纸上写了这段代码。它可以工作,但当我跳转到其他页面时,如何解除此事件的绑定

private-mounted(){
if(process.browser){
const banner:any=document.querySelector(“.banner img”)
document.addEventListener('scroll',()=>{
const offsetTop=window.scrollY
const INTOR_HEIGHT=document.querySelector('.intro text')。offsetHeight
if(偏移<内部高度){
banner.style.top=offsetTop+'px'
}
})
}
}
当我从该页面跳转到其他页面时,会引发以下错误:

javascript未捕获类型错误:无法读取的属性“offsetHeight” 无效的 在HTMLDocument.eval


哈哈,VUE.js实例生命周期挂钩也可以在nuxt.js中使用。 就这样

专用平滑器(){
const banner:any=document.querySelector(“.banner img”)
const offsetTop=window.scrollY
const INTOR_HEIGHT:any=document.querySelector(“.intro text”).offsetHeight
if(偏移<内部高度){
banner.style.top=offsetTop+'px'
}
}
私家车(){
if(process.browser){
document.addEventListener('scroll',this.smoothSlier)
}
}
销毁之前的私有文件(){
document.removeEventListener('scroll',this.smoothSlier)
}
该点是在安装的钩子中绑定golbal事件,并在销毁之前解除绑定