****.vue 文件
methods: {
limitLevel (tree, level) {
if (!tree) return
for (const node of tree) {
if (level === 1) {
delete node.children
} else {
this.limitLevel(node.children, level - 1)
}
}
this.materialCategoryList = tree
},
get***List (id) {
return this.$http.get('/***/****/list').then(({ data: res }) => {
if (res.code !== 0) {
return this.$message.error(res.msg)
}
// tree数据限制到第三级
this.limitLevel(res.data, 3)
this.$nextTick(() => {
this.$refs.tree.setCurrentKey(id)
this.expandedKeys = [id]
})
}).catch(() => {})
},
}