欢迎光临散文网 会员登陆 & 注册

vue-使用lodash库进行函数限流

2023-04-22 00:08 作者:芜湖小量化  | 我要投稿

<template id="Application">
 <div>按钮点击{{count}}次</div>
 <button @click="click">按钮</button>
</template>

<script>
import _ from 'lodash';
export default {
 name: "throttle",
 data(){
   return{
     throttle: false,
     count:0,
   }
 },
 methods:{
   // 因为input输入时需要请求后台,结果每次输入一个字符都会请求,连续输就连续请求 debounce防抖 延时500ms
   click:_.debounce(function () {
     this.count = this.count + 1
   }, 500)
 }
}
</script>

<style scoped>

</style>

vue-使用lodash库进行函数限流的评论 (共 条)

分享到微博请遵守国家法律