建议收藏:vue项目-更改el-tree根据主题色变化,变更选中节点的颜色和背景色
上代码
<style> .s-bg2{ backgound:#eee; } .s-c{ color:bule; } </style> // 根据主题色变换树的颜色 changeTreeAboutTheme(){ let that = this; that.$nextTick(function(){ //先获取节点 let array = document.querySelectorAll('.is-current'); if(array && array.length>0){ for (let i = 0; i < array.length; i++) { const element = array[i]; //将原来的颜色置为无 const content = element.querySelectorAll('.el-tree-node__content'); content[0].style.background = "none"; // 加类,变更 if(element.className.indexOf('s-bg2') === -1){ element.className += " s-bg2 s-c"; } } } }) },