lodash.throttle实现节流
-
安装
yarn install lodash.throttle --save
-
使用
<template>
<div>
test
</div>
</template>
<script>
import throttle from 'lodash.throttle';
export default {
name: 'Test',
mounted() {
window.addEventListener(
'resize',
(this.resize = throttle(this.resizeFun, 100)),
);
},
destroyed() {
if( this.resize )
window.removeEventListener('resize', this.resize);
},
methods: {
resizeFun() {
console.log('视口改变');
},
},
};
</script>