应用场景
使用Ant Design Vue框架开发前端,要求树状table表格默认全部展开。使用expandedRowKeys实现了该目标,但是发现table表格的图标失效了。点击图标无法折叠或展开行
解决办法
使用table组件的 @expand 事件,实现onExpand方法。onExpand即可解决点击图标失效的问题
{{text}}
onExpand (expanded, record) {console.log('extend:' + expanded)console.log('record: ' + JSON.stringify(record))if (expanded) {// 设置展开窗Key,代表展开操作this.expandedRowKeys.push(record.id)} else {// 代表折叠操作if (this.expandedRowKeys.length) {this.expandedRowKeys = this.expandedRowKeys.filter(v => {return v !== record.id})}}},