vue 项目中实现按钮防抖方法
夜久听山雨 人气:01.新建 .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>
加载全部内容