应用场景,动态切换表格列的展示如图
代码实现
首先,不要使用v-show,要使用v-if。
其次,表格加载属于懒加载,所以每次切换内容需要让表格重新加载一次
实现方法,给表格加索引,每次切换改变索引值
<el-table v-loading="listLoading"
:data="list"
border
ref="multipleTable"
fit
style="width: 100%;"
:key="showIndex"
:row-style="rowStyle"
:row-class-name="rowClassName"
@row-click="rowClick"
@selection-change="handleSelectionChange">
<el-table-column :type="typeShow ? 'selection' : 'index'"
align="center"
label="序号"
:selectable="selectable"
width="45">
</el-table-column>
</el-table>
通过按钮切换状态
this.typeShow = !this.typeShow;
this.showIndex = Math.random();