1.新建vue文件存放防抖方法
// 防抖
export const antiShake= (fn, t) => {let delay = t || 500let timerreturn function () {let args = arguments;if (timer) {clearTimeout(timer)}let callNow = !timertimer = setTimeout(() => {timer = null}, delay)if (callNow) fn.apply(this, args)}
}
2.在要加按钮防抖的代码中操作
HTML代码
<el-button class="addTab" type="primary" @click="startDrawPolygon()">新增</el-button>
script代码
//引入防抖文件
import {antiShake} from './utils/utils.js'; //防抖methods: {//给按钮添加防抖startDrawPolygon:antiShake(function(){alert(123)})
}