打赏
Fork me on GitHub

Vue表单提交防抖

首先新增一个js文件,用来放防抖等工具方法

src/utils/index.js

// 防抖
export const Debounce = (fn, t) => {
    let delay = t || 500
    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)
    }
}

引入Debounce

import { Debounce } from '@/utils'

表单提交方法外边套一层 Debuunce 方法

 

methods: {
    Submit: Debounce(function () {
      this.formData.fullname = this.fullname;
      this.formData.sex = this.sex;
      this.formData.count++
    }, 3000)
  }

 

posted @ 2020-06-16 22:46  l-coil  阅读(552)  评论(0编辑  收藏  举报