vue 写一个防抖函数

1152人阅读 2023/7/27 13:40 总访问:680153 评论:0 收藏:0 手机
分类: Vue

前言

 什么是防抖与节流暂时先不说了,我这里直接先记录一下

//定义一个过期的定时器
let timer = setTimeout(function () {

}, 0);
//防抖函数
const debounce = (func,time) => {
  if (timer) {
    clearTimeout(timer);
    timer = setTimeout(function () {
      func();
    }, time);  
  }
}


//调用
  debounce(async () => {
          const resultData = await postUrl('jobManager/CronRead', {}, { cron: cron }).finally(() => {
          })
          console.log("我请求了接口")
          methods.setValue("CronNotes", resultData.data)
        },500)


评价
脚踏实地,一步一个脚印
排名
6
文章
6
粉丝
16
评论
8
{{item.articleTitle}}
{{item.blogName}} : {{item.content}}
ICP备案 :渝ICP备18016597号-1
网站信息:2018-2024TNBLOG.NET
技术交流:群号656732739
联系我们:contact@tnblog.net
欢迎加群交流技术