zoukankan      html  css  js  c++  java
  • 记一次寻找页面卡顿问题

    由于有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
     
     
     
  • 相关阅读:
    c# base64及MD5工具类
    c# dateTime格式转换为Unix时间戳工具类
    c# 金钱大写转小写工具类
    c# bitmap的拷贝及一个图像工具类
    C# DataTable映射成Entity
    Kubernetes---Service(SVC)服务--ingress api
    Kubernetes---Service(SVC)服务
    为网站文字前面添加图标 在线调用 Font Awesome 字体icon小图标 美化网站
    [转]office 2016 4合1/3合1 专业版 增强版 精简绿色安装版
    [转]数据恢复 文件恢复工具 DiskGenius v4.9.1 绿色专业版及单文件
  • 原文地址:https://www.cnblogs.com/gs456/p/11098656.html
Copyright © 2011-2022 走看看