防抖函数
在utils里,debounce.js
function debounce(fun, delay) {
var timer = null;
var delay = delay || 1000;
return function() {
var taht = this; // 注意 this 指向
var args = arguments; // arguments中存着e
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
fun.apply(that,args)
}, delay)
}}
需要用到的组件,引入debounce.js
import {debounce} from "@/utils/debounce"
methods:{
usedebounce: debounce(function(){
//这里写上要执行的方法
},1000)
}
使用就直接 this.usedebounce()