解決iview多表頭動(dòng)態(tài)更改列元素發(fā)生的錯(cuò)誤的方法
解決iview 'You may have an infinite update loop in watcher with expression "columns"'
解決方案
單表頭是可以動(dòng)態(tài)變化不需要增添什么東西

多表頭目前iview尚不能動(dòng)態(tài)變化,會(huì)報(bào)錯(cuò)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>
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
基于vue2.0+vuex的日期選擇組件功能實(shí)現(xiàn)
這篇文章主要介紹了 基于vue2.0+vuex的日期選擇組件功能實(shí)現(xiàn),詳細(xì)介紹了使用vue編寫(xiě)的日期組件,,非常具有實(shí)用價(jià)值,需要的朋友可以參考下。2017-03-03
vue項(xiàng)目動(dòng)態(tài)設(shè)置iframe元素高度的操作代碼
在現(xiàn)代Web開(kāi)發(fā)中,iframe元素常用于嵌入外部?jī)?nèi)容到當(dāng)前網(wǎng)頁(yè)中,比如在線文檔、視頻播放器或是廣告,Vue框架提供了強(qiáng)大的工具來(lái)解決這個(gè)問(wèn)題,通過(guò)動(dòng)態(tài)設(shè)置iframe元素的高度,我們可以確保頁(yè)面布局既美觀又高效,本文給大家介紹了vue項(xiàng)目動(dòng)態(tài)設(shè)置iframe元素高度的操作2024-10-10
Vue組件實(shí)現(xiàn)卡片動(dòng)畫(huà)倒計(jì)時(shí)示例詳解
這篇文章主要介紹了Vue組件實(shí)現(xiàn)卡片動(dòng)畫(huà)倒計(jì)時(shí)示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-07-07
案例實(shí)操vue事件修飾符帶你快速了解與應(yīng)用
這篇文章主要介紹了vue常見(jiàn)的事件修飾符,在平時(shí)無(wú)論是面試還是學(xué)習(xí)工作中都會(huì)經(jīng)常遇到的,本文就帶你快速上手,需要的朋友可以參考下2023-03-03
Vue+Node.js+WebSocket實(shí)現(xiàn)即時(shí)通訊
本文主要介紹了Vue+Node.js+WebSocket實(shí)現(xiàn)即時(shí)通訊,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-05-05
vue-router中關(guān)于children的使用方法
這篇文章主要介紹了vue-router中關(guān)于children的使用方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-08-08
vue打包并部署到nginx上的實(shí)現(xiàn)示例
本文主要介紹了vue打包并部署到nginx上的實(shí)現(xiàn)示例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-01-01
vue用遞歸組件寫(xiě)樹(shù)形控件的實(shí)例代碼
最近在vue項(xiàng)目中遇到需要用樹(shù)形控件的部分,比如導(dǎo)航目錄是不確定的,所以必須要用樹(shù)形結(jié)構(gòu),下面腳本之家小編給大家?guī)?lái)了vue用遞歸組件寫(xiě)樹(shù)形控件的實(shí)例代碼,需要的朋友參考下吧2018-07-07

