onresize 事件被覆盖
采用 window.addEventListener('resize', func)
监听实现
移除 resize 事件
destroyed() {
window.removeEventListener('resize', this.func);
},
实现 resize 防抖
安装 npm i throttle-debounce
库,实现如下
// 节流-防抖
import { debounce } from 'throttle-debounce';
export default {
mounted() {
this.func();
window.addEventListener('resize', this.func);
},
methods: {
func: debounce(400, false, function() {
// 业务代码
}),
}
}