处理之前代码截图
效果展示:
解决方案:
1.在data中定义
data(){
return{
// 是否全部展开,默认为否
isExpand: false,
// 重新渲染表格的状态
refreshTable: true
}
}
2.在el-table中加一个v-if判断
<el-table
v-if="refreshTable"
:data="categoryList"
row-key="id"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
:default-expand-all="isExpand"
>
</el-table>
3.处理控制展开事件(我这里的事件命名是handleExpand,根据自己的事件命名处理)
//全部展开按钮事件
handleExpand() {
this.refreshTable = false;
this.isExpand = true;
this.$nextTick(() => {
this.refreshTable = true;
});
},
效果展示: