• 记一次寻找页面卡顿问题


    由于有3,4个客户说偶尔打开某个组件时会有卡顿现象,所以仔细看了下代码

    这是keyup事件上绑定的代码

    chooseLensSpec: function (event) {
      let num = this.input_num_limit($(event.target).val(), {
        int: 4,
        dec: 0
      })
      if (num === '' && this.pageType === 'inventoryCheck') {
        num = '0'
      }
      $(event.target).val(num)
      let that = this.lens.chosenLists
      if ((num > 0 && this.pageType === 'order') || ((num > 0 || num === '0') && this.pageType === 'inventoryCheck')) {
        let hasSame = false
      for (let i = 0; i < that.length; i++) {
        if (that[i].sph === $(event.target).parents('.sph-row').attr('degree') &&
        that[i].cyl === $(event.target).parents('.cyl-col').attr('degree')) {
        that[i].count = num
        hasSame = true
      }
    }
    if (!hasSame) {
      that.push({
        id: this.id,
        sph: $(event.target).parents('.sph-row').attr('degree').toString(),
        cyl: $(event.target).parents('.cyl-col').attr('degree').toString(),
        count: num,
        bizStock: $(event.target).parents('.cyl-col').find('.bizstock').html()
      })
    }
    } else {
      $(event.target).parent('.cyl-col').removeClass('chosen')
      for (let i = 0; i < that.length; i++) {
        if (that[i].sph === $(event.target).parents('.sph-row').attr('degree') &&
          that[i].cyl === $(event.target).parents('.cyl-col').attr('degree')
        ) {
        that[i].count = num
       }
      }
     }
    }
     
    当选择数量多的时候 每次keyup都会循环一遍40长度以上的数组,遂改之,改为缓存对象索引,以下为修改以后的代码
    chooseLensSpec: function (event,sph,cyl) {
    //设置索引
    let currentClickIdx = `${sph}-${cyl}`

    let num = this.input_num_limit($(event.target).val(), {
      int: 4,
      dec: 0
    })
    if (num === '' && this.pageType === 'inventoryCheck') {
      num = '0'
    }
    $(event.target).val(num)
    let that = this.lens.chosenTempObj
    if(!isNaN(num) && Number(num)!==0){
      that[currentClickIdx] = {
        id: this.id,
        sph: $(event.target).parents('.sph-row').attr('degree').toString(),
        cyl: $(event.target).parents('.cyl-col').attr('degree').toString(),
        count: num,
        bizStock: $(event.target).parents('.cyl-col').find('.bizstock').html()
      }
    }
    else{
      delete that[currentClickIdx]
    }

    },
     
    改完之后发现还是有客户电脑内存占用过高,遂发现点击事件触发DOM操作过多引起的:
    selectLensSpec: function (event,sph,cyl) {
      if(!this.enableSelectLen){
        return
      }

    this.enableSelectLen = false

    var obj = {}
    //设置索引
    let currentClickIdx = `${sph}-${cyl}`

    // this.$nextTick(()=>{
    if (!$(event.target).hasClass('cyl-col')) {
      obj = $(event.target).parents('.cyl-col')
    } else {
      obj = $(event.target)
    }
    obj.toggleClass('chosen')
    if (obj.hasClass('chosen')) {
      let type = this.orderType
    if (this.autoFillInventoryNumber && (type === 'STOCK_RETREAT' || type === 'INVENTORY_OUT') && Number(obj.find('.bizstock').text()) > 0) {
      obj.find('.spec-text').val(obj.find('.bizstock').text()).focus().select()
    } else {
      obj.find('.spec-text').val('1').focus().select()
    }
    } else {
      obj.find('.spec-text').val('')
    }
    let count = obj.find('.spec-text').val()
    this.lens.chosenTempObj[currentClickIdx] = {
      detailId: obj.data('detailid') ? obj.data('detailid').toString() : null,
      id: this.id,
      sph: obj.parents('.sph-row').attr('degree').toString(),
      cyl: obj.attr('degree').toString(),
      count: count,
      bizStock: obj.find('.bizstock').html()
    }
    this.enableSelectLen = true
    // })

    },
     
    重构代价过大,最后决定不改
    ps:老项目jquery转vue是真的烦。。。好多坑 以后少在vue中用jquery
     
     
     
  • 相关阅读:
    企业——给Zabbix部署onealert云告警平台
    企业——使用API在Zabbix监控中实现查看、创建、删除监控主机的功能
    企业——监控平台Zabbix的安装
    企业——Redis的高可用的搭建
    企业——Redis的主从复制的搭建
    企业——MYSQL异步复制、半同步复制、全同步复制
    企业——memcache对PHP页面的缓存加速优化
    企业——HAproxy实现负载均衡及其常见配置
    企业——LVS 负载均衡的八种调度算法
    PHP微信公众号开发之自动回复
  • 原文地址:https://www.cnblogs.com/gs456/p/11098656.html
Copyright © 2020-2023  润新知