表格設(shè)有默認(rèn)展開的key 或者默認(rèn)全部展開奔垦,折疊數(shù)據(jù)后,懶加載請求數(shù)據(jù)后尸疆,被折疊的數(shù)據(jù)還會自動展開椿猎,主要原因是表格數(shù)據(jù)更新了,但是默認(rèn)展開的key不變寿弱,因此還是會自動展開犯眠,解決方案,在收起數(shù)據(jù)后脖捻,把當(dāng)前的key從默認(rèn)展開的key數(shù)組中移除
代碼如下
?<el-table
? ? ? ? :data="tableData"
? ? ? ? :key="tableKey"
? ? ? ? row-key="id"
? ? ? ? stripe
? ? ? ? border
? ? ? ? ref="addressTable"
? ? ? ? style="width: 100%;"
? ? ? ? :height="tableMaxHeight"
? ? ? ? highlight-current-row
? ? ? ? :current-row-key="currentRowKey"
? ? ? ? :expand-row-keys="expandRowKeys"
? ? ? ? :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
? ? ? ? lazy
? ? ? ? :load="childrenLoad"
? ? ? ? @row-click="tableRowClick"
? ? ? ? @expand-change="expandChange"
? ? ? ? v-loading="loading"
? ? ? >
?expandChange (row, expandedRows) {
? ? ? // 解決 折疊后 更新數(shù)據(jù)后 之前的收起項 默認(rèn)又展開了
? ? ? if (!expandedRows) {
? ? ? ? let index = this.expandRowKeys.findIndex(el => el === row.id)
? ? ? ? this.$nextTick(() => {
? ? ? ? ? this.expandRowKeys.splice(index, 1)
? ? ? ? })
? ? ? }
? ? },