===========================================
前端代码
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
name: "Task",
components: {
Treeselect
},
<el-table v-loading="loading" :data="taskList" row-key="taskId" border :row-class-name="tableRowClassName"
:tree-props="{ children: 'children', hasChildren: 'hasChildren' }">
<!-- <el-table-column label="项目ID" align="center" prop="projectId" /> -->
<!-- <el-table-column label="任务父ID" align="center" prop="parentId" />
<el-table-column label="父类模板编号" align="center" prop="ancestors" /> -->
<el-table-column prop="index" width="150" label="序号" align="center">
</el-table-column>
</el-table>
=================js
/** 查询任务总表列表 */
getList() {
this.loading = true;
listTask(this.queryParams).then(response => {
this.taskList = this.handleTree(response.data, "taskId", "parentId");
this.taskList = this.indexData1(this.taskList)
this.loading = false;
});
},
// 排序
indexData1(val) {
console.log(val)
val.forEach((item, index) => {
item.index = index + 1 + '';
if (item.children.length > 0) {
this.indexData2(item, item.index);
}
});
return val;
},
indexData2(item, oldIndex) {
if (item.children.length < 0) return;
if (item.children.length > 0) {
item.children.forEach((Item, i) => {
Item.index = oldIndex + '.' + (i + 1);
this.indexData2(Item, Item.index);
});
}
},