el-tree自带的搜索方法无法展开下级问题

解决办法:

关键在于el-tree里的:filter-node-method="filterNode"

filterNode(value,data,node) {
	//如果共有四级菜单
	if (!value) return true
	let one = data.label.indexOf(value) !== -1
	let two = node.parent && node.parent.data && node.parent.data.label && (node.parent.data.label.indexOf(value) !== -1)
	let three = node.parent && node.parent.parent && node.parent.parent.data && node.parent.parent.data.label && (node.parent.parent.data.label.indexOf(value) !== -1)
	let four= node.parent && node.parent.parent && node.parent.parent.parent && node.parent.parent.parent.data && node.parent.parent.parent.data.label && (node.parent.parent.parent.data.label.indexOf(value) !== -1)
	let result_one = false
	let result_two = false
	let result_three = false
	let result_four = false
	if(node.level === 1) {
		result_one = one
	}else if(node.level === 2) {
		result_two = one || two
	}else if(node.level === 3) {
		result_three = one || two || three
	}else if(node.level === 4) {
		result_three = one || two || three || four
	}
    return result_one || result_two || result_three || result_four
}

注:这里展示是四级的结构,如果结构层数不同,根据方法进行适当的增删

参考链接:element ui Tree搜索显示节点和所有子节点 - 灰信网(软件开发博客聚合)

你可能感兴趣的:(前端,javascript,vue.js)