当前位置: 首页 > news >正文

解决iview多表头动态更改列元素发生的错误

解决iview 'You may have an infinite update loop in watcher with expression "columns"'

解决方案
  • 单表头是可以动态变化不需要增添什么东西

单表头

  • 多表头目前iview尚不能动态变化,会报错You may have an infinite update loop in watcher with expression "columns"解决方法是github大神提供的:需要修改iview.js源码

多表头

将iview.js中

columns: {
    handler: function handler() {
        var colsWithId = this.makeColumnsId(this.columns);
        his.allColumns = (0, _util.getAllColumns)(colsWithId);
        this.cloneColumns = this.makeColumns(colsWithId);

        this.columnRows = this.makeColumnRows(false, colsWithId);
        this.leftFixedColumnRows = this.makeColumnRows('left', colsWithId);
        this.rightFixedColumnRows = this.makeColumnRows('right', colsWithId);
        this.rebuildData = this.makeDataWithSortAndFilter();
        this.handleResize();
        },
     deep: true
   },

修改为

columns: {
     handler: function handler() {
         //[Fix Bug]You may have an infinite update loop in watcher with expression "columns"
         var tempClonedColumns = (0, _assist.deepCopy)(this.columns);
         var colsWithId = this.makeColumnsId(tempClonedColumns);
         //[Fix Bug End]
         this.allColumns = (0, _util.getAllColumns)(colsWithId);
         this.cloneColumns = this.makeColumns(colsWithId);

         this.columnRows = this.makeColumnRows(false, colsWithId);
         this.leftFixedColumnRows = this.makeColumnRows('left', colsWithId);
         this.rightFixedColumnRows = this.makeColumnRows('right', colsWithId);
         this.rebuildData = this.makeDataWithSortAndFilter();
         this.handleResize();
         },
      deep: true
     },
demo
<template>
  <div>
    单表头:
  <Table :columns="columns1" @on-row-click="onRowClick" :data="data1"></Table>
    多表头:
    <Table :columns="columns12" @on-row-click="onRowClick2" :data="data1" border height="500"></Table>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        columns1: [
          {
            title: 'Name',
            key: 'name'
          },
          {
            title: 'Age',
            key: 'age'
          },
          {
            title: 'Address',
            key: 'address'
          }
        ],
        data1: [
          {
            name: 'John Brown',
            age: 18,
            address: 'New York No. 1 Lake Park',
            date: '2016-10-03'
          },
          {
            name: 'Jim Green',
            age: 24,
            address: 'London No. 1 Lake Park',
            date: '2016-10-01'
          },
          {
            name: 'Joe Black',
            age: 30,
            address: 'Sydney No. 1 Lake Park',
            date: '2016-10-02'
          },
          {
            name: 'Jon Snow',
            age: 26,
            address: 'Ottawa No. 2 Lake Park',
            date: '2016-10-04'
          }
        ],
        columns12: [{
          title: 'Name',
          align:'center',
          children: [{
            title: 'nickName',
            key: 'name',
          },
            {
              title: 'realName',
              key: 'name'
            }
          ]
        },
          {
            title: 'Age',
            key: 'age'
          },
          {
            title: 'Address',
            key: 'address'
          }
        ],
      }
    },
    methods: {
      onRowClick() {
        if('City'!==this.columns1[this.columns1.length-1].title) {
          this.columns1.splice(this.columns1.length, 0, {
            title: 'City',
            key: 'address'
          })
        }
      },
      onRowClick2() {
        if('City'!==this.columns12[this.columns12.length-1].title) {
          this.columns12.splice(this.columns12.length, 0, {
            title: 'City',
            key: 'address'
          })
        }
      }
    },
  }
</script>

相关文章:

  • 比特币淘金热席卷中国专业“挖矿机”受疯抢
  • Python的变量和常量
  • PHP——自定义比较算法
  • 【转】Python 内置函数 locals() 和globals()
  • Openssl加密解密应用
  • 敏捷开发的6个实战经验
  • Android 初级面试者拾遗(前台界面篇)之 Activity 和 Fragment
  • MySQL通过命令导出导入数据和表
  • python列表中的深浅copy
  • mysql高可用方案之主从架构(master-slave)
  • 中国HBase技术社区第二届MeetUp ——HBase技术解析及应用实践
  • Centos 7.4 安装 Redis 全过程
  • cocos2d-x引擎库binary版本制作(Windows环境)
  • 解决jsfl 弹出警告
  • 基于HTML5技术的电力3D监控应用(一)
  • [译]前端离线指南(上)
  • [原]深入对比数据科学工具箱:Python和R 非结构化数据的结构化
  • golang中接口赋值与方法集
  • Laravel深入学习6 - 应用体系结构:解耦事件处理器
  • Mithril.js 入门介绍
  • Octave 入门
  • spring + angular 实现导出excel
  • Spring框架之我见(三)——IOC、AOP
  • Transformer-XL: Unleashing the Potential of Attention Models
  • vue2.0开发聊天程序(四) 完整体验一次Vue开发(下)
  • Vue实战(四)登录/注册页的实现
  • webgl (原生)基础入门指南【一】
  • Webpack4 学习笔记 - 01:webpack的安装和简单配置
  • 关于extract.autodesk.io的一些说明
  • 那些被忽略的 JavaScript 数组方法细节
  • 前端存储 - localStorage
  • 三分钟教你同步 Visual Studio Code 设置
  • 移动互联网+智能运营体系搭建=你家有金矿啊!
  • 自动记录MySQL慢查询快照脚本
  • 如何通过报表单元格右键控制报表跳转到不同链接地址 ...
  • ​人工智能之父图灵诞辰纪念日,一起来看最受读者欢迎的AI技术好书
  • # 深度解析 Socket 与 WebSocket:原理、区别与应用
  • (+4)2.2UML建模图
  • (floyd+补集) poj 3275
  • (HAL库版)freeRTOS移植STMF103
  • (Repost) Getting Genode with TrustZone on the i.MX
  • (附源码)计算机毕业设计SSM基于健身房管理系统
  • (一)80c52学习之旅-起始篇
  • (一)基于IDEA的JAVA基础12
  • .bat文件调用java类的main方法
  • .net core 6 集成和使用 mongodb
  • .net on S60 ---- Net60 1.1发布 支持VS2008以及新的特性
  • .NET 读取 JSON格式的数据
  • .net通用权限框架B/S (三)--MODEL层(2)
  • .Net下使用 Geb.Video.FFMPEG 操作视频文件
  • .net用HTML开发怎么调试,如何使用ASP.NET MVC在调试中查看控制器生成的html?
  • /etc/skel 目录作用
  • ::before和::after 常见的用法
  • @Transient注解
  • [ solr入门 ] - 利用solrJ进行检索