二次修改了一下,确保点击某一单元格格元素触发
javascript">// 隐藏懒加载箭头后手动触发懒加载
expandRows(scope){scope.row.isExpanded = !scope.row.isExpanded // 切换展开状态let isExpanded = scope.row.isExpandedconst { table: { toggleRowExpansion, store }} = this.$refs;const { states: { lazy, treeData, rowKey }, assertRowKey, loadData } = store const id = getRowIdentity(scope.row, rowKey)const data = treeData[id]if (isExpanded) {// 懒加载则调用懒加载if (lazy && data && 'loaded' in data && !data.loaded) {return loadData(scope.row, id, data)}}// 其余调用el-table的展开方法return toggleRowExpansion(scope.row, isExpanded)function getRowIdentity(row, rowKey) {if (!row) throw new Error('row is required when get row identity');if (typeof rowKey === 'string') {if (rowKey.indexOf('.') < 0) {return row[rowKey];}let key = rowKey.split('.');let current = row;for (let i = 0; i < key.length; i++) {current = current[key[i]];}return current;} else if (typeof rowKey === 'function') {return rowKey.call(null, row);}}
}
参考链接:el-table 树形数据 懒加载模式下一键展开_togglerowexpansion lazy-CSDN博客