Skip to content

防止多次表单提交的简单方法 #13

@arcsin1

Description

@arcsin1
const createThrottleProxy = (fn, rate) => {
  let lastClick = Date.now() - rate
  return new Proxy(fn, {
    apply(target, context, args) {
      if (Date.now() - lastClick >= rate) {
        fn(args)
        lastClick = Date.now()
      }
    },
  })
}
clickMe = () => {
    console.log('132423525')
  }
 <Button onClick={createThrottleProxy(this.clickMe, 3000)}>提交</Button>

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions