样式效果如上
<el-tree :data="treedata" :props="defaultProps" :expand-on-click-node="false" :current-node-key="currentNodekey" :default-expanded-keys="expandedkeys" accordion highlight-current node-key="id" ref="tree" @node-click="handleNodeClick" ></el-tree>
treedata: [], //树结构数据 defaultProps: { children: "children", label: "label" }, currentNodekey: "", //默认选中的节点树 expandedkeys: [], //默认展开的节点树
接口返回数据res.data
this.treedata = res.data; //知识点树 if(this.treedata.length>0){ this.currentNodekey = this.treedata[0].id; this.expandedkeys.push(this.treedata[0].id);
this.$refs.tree.setCurrentKey(this.currentNodekey);//一定要加这个选中了否则样式没有出来 }
最后加个样式,让他选中样式是加粗的蓝色
.el-tree--highlight-current .el-tree-node.is-current>.el-tree-node__content { color: #4d95fd; font-weight: bold; }