zoukankan      html  css  js  c++  java
  • 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)
      }
    博客园:https://www.cnblogs.com/xianquan
    Copyright ©2020 l-coil
    【转载文章务必保留出处和署名,谢谢!】
查看全文
  • 相关阅读:
    IIC/I2C从地址之7位,8位和10位详解
    ARM uxtw
    ARM(CM3)的汇编指令
    WZR/XZR ARM
    LDR r, label 和 LDR r, =label的区别
    Distinguishing between 32-bit and 64-bit A64 instructions
    03JavaScript程序设计修炼之道_2019-06-18_20-39-14_事件onload&onmouseover&out
    02-CSS基础与进阶-day6_2018-09-05-20-18-21
    02-CSS基础与进阶-day5_2018-09-03-22-10-39
    02-CSS基础与进阶-day5_2018-09-03-21-41-57
  • 原文地址:https://www.cnblogs.com/xianquan/p/13149685.html
  • Copyright © 2011-2022 走看看