vue3 element-plus el-tree自定義圖標方式
更新時間:2024年03月19日 08:36:56 作者:隨便叫個啥呢
這篇文章主要介紹了vue3 element-plus el-tree自定義圖標方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vue3 element-plus el-tree自定義圖標
樹組件
<template> <div class="left-tree"> <el-tree :data="treeData.data" node-key="id" :props="defaultProps" :default-expanded-keys="[0]" :default-checked-keys="[0]" @node-click="nodeclick" > <template #default="scope"> <div class="custom-node"> <i class="tree-icon" :class="{ 'el-icon-caret-right': !scope.node.expanded, 'el-icon-caret-bottom': scope.node.expanded, 'el-icon-wlj-yuandian': scope.data.is_leaf === 1 }" :style="{ color: scope.data.is_leaf === 1 ? 'rgb(54,229,150)' : '#409eff' }" /> <span>{{ scope.node.label }}</span> </div> </template> </el-tree> </div> </template>
<script lang="ts" setup> import { onMounted, reactive } from "vue"; import { getDept } from "@/api/asset" // 定義派發(fā)事件 const emit = defineEmits(['tree-node-click']) const nodeclick = (data, node, component) => { // console.log('子組件category的節(jié)點被點擊', data, node, component) // 向父組件發(fā)送事件; emit('tree-node-click', data, node, component) } let defaultProps = reactive({ children: 'children', label: 'name', }) let treeData: any = reactive({ data: [] }) async function getDeptTree() { const data: any = await getDept({ POST_TYPE: 1 }) treeData.data = data.lists console.log(treeData) } onMounted(async () => { getDeptTree() }) </script>
<style lang="scss" scoped> //tree .el-tree-node__content:hover { background-color: rgb(255, 207, 131); } .el-tree-node:focus > .el-tree-node__content { background-color: rgb(255, 207, 131); } .el-tree-node__label { font-size: 1.5vh; } .el-tree-node__expand-icon { color: transparent; cursor: default; } //tree .left-tree { height: 73vh; overflow: auto; } /*修改滾動條樣式*/ .left-tree::-webkit-scrollbar { width: 10px; height: 10px; /**/ } .left-tree::-webkit-scrollbar-track { background: rgb(104, 108, 143); border-radius: 10px; } .left-tree::-webkit-scrollbar-thumb { background: rgb(54, 229, 150); border-radius: 10px; } // .left-tree::-webkit-scrollbar-thumb:hover{ // background: #333; // } // .left-tree::-webkit-scrollbar-corner{ // background: #179a16; // } .tree-icon { margin-right: 1vh; margin-left: -2vh; } .el-tree { background: none; color: #fff; } </style>
父組件
<dept-tree @tree-node-click="treenodeclick"/> const treenodeclick = (data, node, component) => { console.log(data); }
總結
以上為個人經驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關文章
VueJs中的shallowRef與shallowReactive函數(shù)使用比較
這篇文章主要為大家介紹了VueJs中的shallowRef與shallowReactive函數(shù)的使用比較解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-04-04