二次修改了一下,確保點擊某一單元格格元素觸發
// 隱藏懶加載箭頭后手動觸發懶加載
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博客