debounce.js 963 B

1234567891011121314151617181920212223242526272829303132
  1. // +----------------------------------------------------------------------
  2. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  3. // +----------------------------------------------------------------------
  4. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  5. // +----------------------------------------------------------------------
  6. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  7. // +----------------------------------------------------------------------
  8. // | Author: CRMEB Team <admin@crmeb.com>
  9. // +----------------------------------------------------------------------
  10. export default {
  11. data() {
  12. return {};
  13. },
  14. created() {},
  15. methods: {
  16. Debounce(fn, t) {
  17. const delay = t || 500
  18. let timer
  19. return function() {
  20. const args = arguments
  21. if (timer) {
  22. clearTimeout(timer)
  23. }
  24. timer = setTimeout(() => {
  25. timer = null
  26. fn.apply(this, args)
  27. }, delay)
  28. }
  29. }
  30. }
  31. };