1. 程式人生 > >debounce函式防抖

debounce函式防抖

實現

function debounce(callback,time){
   let timer;
    return function(){
        window.clearTimeout(timer)
        timer=window.setTimeout(function(){
            callback()
        },time)
    }
}

應用

下載lodash

npm i -S lodash

配置

 externals:{
        lodash:'_'
    }

引用

import lodash from
'lodash' methods:{ checkEmail:_.debounce(async function(){ const {data}=await axios.get(`/api/users`) },500)