在 mounted 中给 vue 添加了一个事件监听,然后再 beforedestory 中移除事件监听,发现移除事件监听失败
后来发现想要移除 window 的 addEventListener,需要把后面的 function 挂在到 this 上
mounted () {window.addEventListener('resize', this.listenResize)
},
beforeDestroy () {window.removeEventListener('resize', this.listenResize)
}
listenResize 方法我定义在 methods 中
具体请参考 baoleilei6 的文章