input输入框防抖处理

94 篇文章 2 订阅
84 篇文章 0 订阅

input事件是实时监听输入内容的变化,这就造成重复触发的问题。

searchInput(e) {
            let that = this
            let _parm = ''
            if (typeof e != 'undefined') {
                _parm = e;
                console.log('ee',e,that.searchContent)
            }
            clearTimeout(this.timer);// 清除
            that.timer =  setTimeout(() => {
                that.$store
                .dispatch('home_panel_list', { searchContent: that.searchContent })
                .then((res) => {
                    console.log(res)
                    if(res && res['result'] && Array.isArray(res.result) && res.result.length > 0){
                        let _panelList = res.result;
                        _panelList.map(function(item, index){
                            item['moduleId'] = item['id'];
                            item['moduleName'] = item['plateName'];
                            item['moduleKey'] = item['plateKey'];
                            // item['moduleIcon'] = that.getModuleIcon(item['plateKey']);

                            if(item['permissionsSubset']){//权限
                            let _permissionsSubset = eval('(' + item.permissionsSubset + ')');
                            if(item.moduleKey === 'logical_subject' || item.moduleKey === 'system_setup' || item['plateKey'] == 'relationship'){//系统配置、档案管理
                                item['permissionsArr'] = _permissionsSubset;
                                if(item.moduleKey === 'logical_subject'){
                                that.archiveArr = item.permissionsArr;
                                //存储进localStorage里面,刷新的时候,也去localStorage里面取出来
                                Utils.setLocalCache(TYPES.COOKIE_PERMISSION_UNIT + '_' + that.user_info['userId'], that.archiveArr);
                                that.goToArchive();//获取archiveStr
                                }
                                if(item.moduleKey === 'system_setup') item['pathName'] = that.$router.options.getRoute(item.moduleKey);
                            }else if(_permissionsSubset.length === 1){//项目用户的项目一览也是1,如何区分?
                                item['permissionsStr'] = _permissionsSubset[0];
                                // let key = that.getKey(_permissionsSubset[0]);
                                // item['pathName'] = that.$router.options.getRoute(key);
                                // console.log(key, item.pathName);
                            }/*else if(item['plateKey'] == 'relationship'){
                                item['permissionsStr'] = '';
                            }*/
                            }
                            if('undefined' !== typeof item['classifyId']){
                            if(that.funcModules[item.classifyId] && that.funcModules[item.classifyId]['typeArr']
                                && 'undefined' !== typeof item['isShow'] && item.isShow === 1){
                                if(item['plateKey'] != 'Console') that.funcModules[item.classifyId]['typeArr'].push(item)
                            }
                            }
                            return item;
                        });
                        that.funcModules.map(function(item){
                            if(item['typeArr'] && Array.isArray(item.typeArr) && item.typeArr.length > 0){
                            item.typeArr.sort(Utils.sortBy('orderSort', false, parseInt));
                            }
                            return item;
                        })
                        that.menuRecommend = _panelList;
                    }
                    
                })
                .catch((err) => {
                    console.log(err)
                })
            }, 800);
            
        },

使用clearTimeout来清除之前的请求,settimeout时间可以根据需求自己设定。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

第7个前端

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值