1.新建 .js文件存放防抖方法

// 防抖
export const antiShake= (fn, t) => {
  let delay = t || 1000
  let timer
  return function () {
    let args = arguments;
    if (timer) {
      clearTimeout(timer)
    }
 
    let callNow = !timer
 
    timer = setTimeout(() => {
      timer = null
    }, delay)
 
    if (callNow) fn.apply(this, args)
  }
}

2.引入防抖文件,methods中添加方法

//引入防抖文件
import { antiShake } from '../../../../common/antiShake.js'; //防抖

methods: {  
         //给按钮添加防抖
        startDrawPolygon: antiShake(function () {
            this.getDepartments() //按钮触发的方法
        }),
}

3.html代码

<el-button @click="startDrawPolygon()" style="background-color:#409EFF; color: #FFF;" slot="append" icon="el-icon-search">搜索</el-button>
原文地址:https://www.cnblogs.com/chenxdnote/p/16969302.html

相关文章:

  • 2022-12-23
  • 2023-02-27
  • 2023-01-10
  • 2021-04-20
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-01-22
  • 2021-12-11
  • 2022-12-23
  • 2023-02-12
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案