vue封装utils之防抖
// src/common/js/utils.js
let _debounceTimeout = null,
_throttleRunning = false;
/**
*防抖
*@params{Function}执行函数
*@params{Number} delay 延时ms
*/
export const debounce = (fn,delay = 500) => {
clearTimeout(_debounceTimeout);
_debounceTimeout = setTimeout(() => {
fn();
},delay)
}
// main.js
import{debounce} from '@/common/js/utils'
Vue.prototype.$util = {
debounce
}
// index.vue
methods:{
inputFocus(){
this.$util.debounce(this.$util.debounce(this.initData, 500))
}
initData(){
console.log('输入框foces,搜索数据ing')
}
}