click1(){
if(this.orderSuccess){
click()
}}
click(){
clearTimeout(this.timeOut)
this.orderSuccess = false
this.timeOut = setTimeout(()=>{
this.orderSuccess = true
},5000)
}
请问vue里这样的节流方式有什么弊端?
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
关注 你这个定时器完全没必要写在data里,不然vue还得对你这个数据拦截进行响应式处理,消耗性能
直接在click1方法里声明一个定时器就好了,click方法使用了click1的数据形成了闭包
click1(){
let timer = null
if(this.orderSuccess){
click(timer )
}}click(timer ){
clearTimeout(this.timeOut)
this.orderSuccess = false
timer = setTimeout(()=>{
this.orderSuccess = true
},5000)
}如有帮助,望采纳^.^ 谢谢啦
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 编辑记录
悬赏问题
- ¥15 weditor无法连接模拟器Local server not started, start with?
- ¥20 6-3 String类定义
- ¥15 嵌入式--定时器使用
- ¥15 基于OPENCV的人脸识别
- ¥20 51单片机学习中的问题
- ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
- ¥15 Python中knn问题
- ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库
- ¥15 C# datagridview 单元格显示进度及值
- ¥15 thinkphp6配合social login单点登录问题