element-tree-line el-tree 添加结构线 添加虚线

概览:给element组件添加上虚线,通过使用插件element-tree-line

参考连接:

参考别人的博客

安装插件:

npm

npm install element-tree-line -S

yarn

yarn add element-tree-line -S

main.js全局注册引入插件:

javascript 复制代码
import { getElementLabelLine } from 'element-tree-line';
import 'element-tree-line/dist/style.css';
const ElementLabelLine = getElementLabelLine(h);
app.component(ElementLabelLine.name, ElementLabelLine);

el-tree组件封装:

html 复制代码
<template>
    <el-tree ref="treeRef" class="tree-content" :data="props.treeData" node-key="id" :highlight-current="true"
        :props="props.defaultProps" icon="none" :current-node-key='0' default-expand-all :indent="props.treeIndent">
        <template #default="{ node, data }">
            <element-tree-line :node="node" :showLabelLine="false" :indent="props.treeIndent">
                <template v-slot:node-label>
                    <div class="com-tree">
                        <i v-if="data.children?.length > 0"
                            :class="node.expanded ? 'iconfont icon-pinleijianshao' : 'iconfont icon-pinleizengjia'"
                            class="tree-icon"></i>
                        <span class="com-tree-text" @click="nodeClick(data)">{{ node.label }}</span>
                    </div>
                </template>
            </element-tree-line>
        </template>
    </el-tree>
</template>

<script setup>
let props = defineProps({ treeData: Array, defaultProps: Object, treeIndent: Number });
const emits = defineEmits(['nodeClick']);
const nodeClick = (data) => {
    emits('nodeClick', data);
};
</script>

el-tree页面组件使用:

html 复制代码
<el-scrollbar>
        <Tree 
            :treeData="data.treeData" 
            :defaultProps="defaultProps" 
            :treeIndent="data.treeIndent"
            @nodeClick="hanleNodeClick">
        </Tree>
</el-scrollbar>

效果展示:

相关推荐
酒尘&2 小时前
JS数组不止Array!索引集合类全面解析
开发语言·前端·javascript·学习·js
用户47949283569153 小时前
"讲讲原型链" —— 面试官最爱问的 JavaScript 基础
前端·javascript·面试
用户47949283569153 小时前
2025 年 TC39 都在忙什么?Import Bytes、Iterator Chunking 来了
前端·javascript·面试
JIngJaneIL4 小时前
基于Java非遗传承文化管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot
+VX:Fegn08954 小时前
计算机毕业设计|基于springboot + vue心理健康管理系统(源码+数据库+文档)
数据库·vue.js·spring boot·后端·课程设计
大怪v4 小时前
【Virtual World 04】我们的目标,无限宇宙!!
前端·javascript·代码规范
蓝瑟7 小时前
告别重复造轮子!业务组件多场景复用实战指南
前端·javascript·设计模式
老华带你飞7 小时前
旅游|基于Java旅游信息系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·旅游
韭菜炒大葱8 小时前
别等了!用 Vue 3 让 AI 边想边说,字字蹦到你脸上
前端·vue.js·aigc
渴望成为python大神的前端小菜鸟8 小时前
浏览器及其他 面试题
前端·javascript·ajax·面试题·浏览器