欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue 項(xiàng)目中實(shí)現(xiàn)按鈕防抖方法

 更新時(shí)間:2022年12月13日 15:37:35   作者:夜久聽山雨  
這篇文章主要介紹了vue 項(xiàng)目中實(shí)現(xiàn)按鈕防抖方法,首先需要新建 .js文件存放防抖方法,引入防抖文件,methods中添加方法,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下

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() //按鈕觸發(fā)的方法
        }),
}

3.html代碼

<el-button @click="startDrawPolygon()" style="background-color:#409EFF; color: #FFF;" slot="append" icon="el-icon-search">搜索</el-button>

到此這篇關(guān)于vue 項(xiàng)目中實(shí)現(xiàn)按鈕防抖的文章就介紹到這了,更多相關(guān)vue 按鈕防抖內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論