在vue中多个组件中都使用window.onresize=()=>{},会导致前边赋值的方法被覆盖掉
改成 window.removeEventListener('resize', ()=>{}) 可生效
methods: { myFunction() { ... } }, mounted(){ // 新增监听事件,如果带参数的函数,只能套一层。 window.addEventListener('resize', this.myFunction) }, destroyed () { // 移除监听事件 window.removeEventListener('resize', this.myFunction) }