Utils 工具库 - Optimization截流防抖

截流防抖

#截流

#throttle
  • 示例代码:
<template>
    <div class="wrapper">
        <text>throttle: 截流函数</text>
    </div>
</template>
<script>
export default {
    data:()=> ({
        name: 'deepCopy',
    }),
    methods: {
        throttleHandler() {
            //函数截流
            let res = this.$util.throttle(()=> {
                this.$toast('hello, dolphinWeex !')
            },1000)
        }
    }
}
</script>
<style scoped>
.wrapper{
    background-color: #ffffff;
}
</style>

#参数

  • 参数详情:
Params Type Required default Value
func any Y - 要执行的方法
wait Number N 500 延时的时间
immediate Boolean N true 是否立即执行

#防抖

#debounce
  • 示例代码:
<template>
    <div class="wrapper">
        <text>debounce: 防抖</text>
    </div>
</template>
<script>
export default {
    data:()=> ({
        name: 'debounce',
    }),
    methods: {
        debounceHandler() {
            //函数截流
            let res = this.$util.debounce(()=> {
                this.$toast('hello, dolphinWeex !')
            },1000)
        }
    }
}
</script>
<style scoped>
.wrapper{
    background-color: #ffffff;
}
</style>

#参数

  • 参数详情:
Params Type Required default Value
func any Y - 要执行的方法
wait Number N 500 延时的时间
immediate Boolean N true 是否立即执行
posted on 2024-12-13 09:19  AtlasLapetos  阅读(15)  评论(0)    收藏  举报