vue代码
防抖

// timer用于储存定时器
delayed(){
    // 检测定时器
    if(this.timer){
        // 如果有定时器,则清除
        clearTimeout(this.timer)
        this.timer=null
    }
    // 设置定时器和事件
    this.timer=setTimeout(()=>{
        // do something
    },500)
}

节流

test(){
    let that=this
    if(that.stopClickLogin){
        console.log(`请等待1s后再次点击 >>>>>>>>>`)
        return false
    }
    that.stopClickLogin=true
    setTimeout(()=>{
        that.stopClickLogin=false
    },1000)
    console.log(`do something >>>>>>>>>`)
}