Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
arcsin1 opened this issue Dec 26, 2017 · 0 comments
Open

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

arcsin1 opened this issue Dec 26, 2017 · 0 comments
Labels

Comments

@arcsin1
Copy link
Owner

arcsin1 commented Dec 26, 2017

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>
@arcsin1 arcsin1 added the JS label Dec 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant