1、介绍

使用最新的vue-cli搭建脚手架,使用最新的vue-router4, 使用scss预处理器,

2、组件条目

  • Button 组件
  • Banner3D 组件
  • 轮播图 组件
  • Table 组件
  • 树组件

3、vue3 自定义指令

自定义节流指令

main.ts

  1. import { throttle } from "./utile"
  2. // vue3 注册自定义指令
  3. app.directive('throttle', {
  4. beforeMount(el, binding) {
  5. const [func, timer] = binding.value;
  6. el.addEventListener('click', throttle(func, timer));
  7. }
  8. });

util/index.ts

  1. // 函数的节流
  2. export function throttle(func: Function, wait: number = 500) {
  3. let timer: number | null,
  4. previous: any = 0;
  5. return function anonymous(...params: any[]) {
  6. let now: any = new Date(),
  7. that: any,
  8. remaining = wait - (now - previous);
  9. if (remaining <= 0) {
  10. clearTimeout(timer as number);
  11. timer = null;
  12. previous = now;
  13. func.call(that, ...params);
  14. } else if (!timer) {
  15. timer = setTimeout(() => {
  16. clearTimeout(timer as number);
  17. timer = null;
  18. previous = new Date();
  19. func.call(that, ...params);
  20. }, remaining);
  21. }
  22. };
  23. }

使用

  1. <a
  2. href="javascript:;"
  3. class="arrow arrow-left"
  4. v-throttle="[change.bind(null, 'left'), 500]"
  5. >
  6. </a>