sf-utils2 sf-utils2
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
版本v3.3.3-beta1
首页
  • 01.快速开始 🔥
  • 02.基础-Base
  • 03.对象-Object
  • 04.数组-Array
  • 05.方法-Function
  • 06.字符串-String
  • 07.数学-Math
  • 08.dom
  • 09.拓展
  • webpack5.x教程学习 (opens new window)
  • 例子
  • 教程 🔥
  • 例子配置
企业级后台模版 (opens new window)
  • 快速开始

  • 基础-Base

  • 对象-Object

  • 数组-Array✨✨✨

  • 方法-Function

    • 序言 👏
    • debounceDtor【去抖装饰器】
      • 1.示例
      • 2.入参说明
      • 3.源码
    • throttleDtor【截流装饰器】
    • throttle【截流】
    • debounce【去抖】
    • to【异步错误处理】🔥🔥🔥
    • queuePromises【执行异步队列】
  • 字符串-String

  • 数学-Math

  • 文件-Buffer

  • 节点-dom

  • 拓展

  • nodejs

目录

debounceDtor【去抖装饰器】

描述

截流装饰器

# 1.示例

调整窗口大小,然后请打开控制台查看打印日志
<template>
  <div>
    <el-divider>调整窗口大小,然后请打开控制台查看打印日志</el-divider>
  </div>
</template>

<script>
import { debounceDtor } from 'sf-utils2'
export default {
  mounted() {
    window.addEventListener('resize', this.onResize, false)
  },

  methods: {
    @debounceDtor(500)
    onResize() {
      console.log('监听到窗口发生变化')
    }
  },

  beforeDestroy() {
    window.removeEventListener('resize', this.onResize, false)
  }
}
</script>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
显示代码 复制代码 复制代码

# 2.入参说明

参数 说明 类型 是否必填 默认值
wait 去抖时间 Number 300

# 3.源码

import debounce from '@/function/debounce'

/**
 * 函数节流装饰器
 * @param {number} wait 节流的毫秒
 * @param {Object|Boolean} options 参数{leading: 是否在之前执行, trailing: 是否在之后执行} 默认在定时器之后执行 trailing = true
 */
function debounceDtor(wait = 300, options) {
  return function (target, name, descriptor) {
    descriptor.value = debounce(descriptor.value, wait, options)
  }
}

export default debounceDtor
1
2
3
4
5
6
7
8
9
10
11
12
13
14
上次更新: 2023/06/24, 19:35:48
序言 👏
throttleDtor【截流装饰器】

← 序言 👏 throttleDtor【截流装饰器】→

Theme by Vdoing | Copyright © 2022-2025 bianpengfei
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×