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)

猜你喜欢

转载自blog.csdn.net/zhong242526/article/details/80403235