util.js 510 B

1234567891011121314151617181920
  1. // 防抖函数
  2. function debounce(func, wait) {
  3. let timeout;
  4. return function (...args) { // 使用剩余参数语法接收所有传入的参数
  5. clearTimeout(timeout); // 清除上一个定时器
  6. timeout = setTimeout(() => {
  7. func.apply(this, args); // 使用apply来调用原始函数,并传入当前this值和所有参数
  8. }, wait);
  9. };
  10. }
  11. // 获取页面元素
  12. const getElement = (id) => {
  13. const element = echarts.init(
  14. document.getElementById(id)
  15. );
  16. return element
  17. }