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


Posted in Javascript onNovember 02, 2018

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

解决方案

单表头是可以动态变化不需要增添什么东西

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

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

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

将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>

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Javascript 相关文章推荐
javascript 面向对象编程基础:继承
Aug 21 Javascript
Mootools 1.2教程 滑动效果(Slide)
Sep 15 Javascript
js获取RadioButtonList的Value/Text及选中值等信息实现代码
Mar 05 Javascript
JavaScript实现找质数代码分享
Mar 24 Javascript
JavaScript实现的类字典插入或更新方法实例
Jul 10 Javascript
JS全局变量和局部变量最新解析
Jun 24 Javascript
js获取Get值的方法
Sep 29 Javascript
微信小程序链接传参并跳转新页面
Nov 29 Javascript
vue时间格式化实例代码
Jun 13 Javascript
前端MVVM框架解析之双向绑定
Jan 24 Javascript
详解vue中async-await的使用误区
Dec 05 Javascript
解决VUEX的mapState/...mapState等取值问题
Jul 24 Javascript
JavaScript 点击触发复制功能实例详解
Nov 02 #Javascript
微信小程序实现留言板(Storage)
Nov 02 #Javascript
微信小程序实现留言板功能
Nov 02 #Javascript
小程序实现留言板
Nov 02 #Javascript
js中的闭包实例展示
Nov 01 #Javascript
微信小程序实现登录遮罩效果
Nov 01 #Javascript
在vue里使用codemirror遇到的问题
Nov 01 #Javascript
You might like
CodeIgniter输出中文乱码的两种解决办法
2014/06/12 PHP
php将textarea数据提交到mysql出现很多空格的解决方法
2014/12/19 PHP
PHP6连接SQLServer2005的三部曲
2016/04/15 PHP
PHP集成环境XAMPP的安装与配置
2018/11/13 PHP
JavaScript版代码高亮
2006/06/26 Javascript
JavaScript创建一个欢迎cookie弹出窗实现代码
2013/03/15 Javascript
JS操作Cookies的小例子
2013/10/15 Javascript
jquery实现背景墙聚光灯效果示例分享
2014/03/02 Javascript
javascript实现checkbox复选框实例代码
2016/01/10 Javascript
解析Node.js异常处理中domain模块的使用方法
2016/02/16 Javascript
jQuery多选框选择数量限制方法
2017/02/08 Javascript
JS实现颜色动态淡化效果
2017/03/06 Javascript
微信小程序 实现列表项滑动显示删除按钮的功能
2017/04/13 Javascript
Vue报错:Uncaught TypeError: Cannot assign to read only property’exports‘ of object’#‘的解决方法
2017/06/17 Javascript
js中变量的连续赋值(实例讲解)
2017/07/08 Javascript
微信小程序中post方法与get方法的封装
2017/09/26 Javascript
Node.js利用断言模块assert进行单元测试的方法
2017/09/28 Javascript
vue插件实现v-model功能
2018/09/10 Javascript
小程序云开发实现数据库异步操作同步化
2019/05/18 Javascript
在Python的web框架中中编写日志列表的教程
2015/04/30 Python
Python爬虫设置代理IP的方法(爬虫技巧)
2018/03/04 Python
numpy 对矩阵中Nan的处理:采用平均值的方法
2018/10/30 Python
python random从集合中随机选择元素的方法
2019/01/23 Python
对Python中的条件判断、循环以及循环的终止方法详解
2019/02/08 Python
python3实现二叉树的遍历与递归算法解析(小结)
2019/07/03 Python
在python中,使用scatter绘制散点图的实例
2019/07/03 Python
Django 自定义权限管理系统详解(通过中间件认证)
2020/03/11 Python
Nike挪威官网:Nike.com (NO)
2018/11/26 全球购物
公司总经理工作职责管理办法
2014/02/28 职场文书
护士个人自我鉴定
2014/03/24 职场文书
幼儿园校园小喇叭广播稿
2014/10/17 职场文书
2014年企业党建工作总结
2014/12/18 职场文书
焦裕禄纪念馆观后感
2015/06/09 职场文书
暂住证证明
2015/06/19 职场文书
《蟋蟀的住宅》教学反思
2016/02/17 职场文书
《天使的翅膀》读后感3篇
2019/12/20 职场文书