<template>
<div>
<el-tree
node-key="id"
lazy
:load="loadNode"
:props="defaultProps"
:expand-on-click-node="false"
:check-on-click-node="true"
v-loading="list.loading"
@node-click="nodeClick"
ref="tree"
>
</el-tree>
</div>
</template>
<script>
import axios from "axios";
export default {
data() {
return {
list: {
loading: false,
isExpand: false,
},
defaultProps: {
children: "children",
label: "name",
isLeaf: "leaf",
},
loading: false,
curPath:'',
curNode:''
};
},
methods: {
nodeClick(data, node) {
this.curPath = data.path;
this.curNode = node;
},
partialRefreshpartialRefresh(node) {
node.loaded = false;
node.expand();
},
async loadNode(node, resolve) {
return resolve(await this.getTagList(node, resolve))
},
async getTagList(node, resolve) {
var level = ''
console.log(67,node);
if(node.level==0){
level='zxt'
}else if(node.level==1){
level='zxtb'
}else{
level='zxtc'
}
console.log(node.level,level);
this.list.loading = true;
const res = await axios.get(
`https://www.fastmock.site/mock/9846b0461be6cbf4f1dfd50fd4b9b0bb/tree/${level}`
);
const tags = res.data.data;
tags.forEach((item, index) => {
item.name = item.label;
item.id = index;
item.leaf = false;
});
this.list.loading = false;
console.log(55, tags);
return tags;
},
async getTagApiList(tag) {
const res = await axios.get(
"https://www.fastmock.site/mock/9846b0461be6cbf4f1dfd50fd4b9b0bb/tree/zxtb"
);
const results = res.data.data;
console.log(85,results);
results.forEach((item) => {
item.name = item.label;
item.id;
item.leaf = true;
});
return results;
},
async TagApiList(tag) {
const res = await axios.get(
"https://www.fastmock.site/mock/9846b0461be6cbf4f1dfd50fd4b9b0bb/tree/zxtc"
);
const results = res.data.data;
console.log(103,results);
results.forEach((item) => {
item.name = item.label;
item.id;
item.leaf = true;
});
return results;
},
},
};
</script>
<style>
</style>
|