19vue3实战-----菜单子树的展示

devtools/2025/2/13 12:44:53/

19vue3实战-----菜单子树的展示

  • 1.实现目标
  • 2.实现思路
  • 3.实现步骤
    • 3.1新建config配置文件
    • 3.2封装组件
    • 3.3使用组件

1.实现目标

在这里插入图片描述
如上,以上效果的难点是“在表格里面实现树形结构”。可以用element-plus框架中的table作为辅助:
在这里插入图片描述
可以自己查看文档了解怎么使用。

2.实现思路

上面的效果不难实现,无非就是搭建界面。这里我不用常规方法“一个一个页面搭建”,而是用之前写的文章https://blog.csdn.net/fageaaa/article/details/145572470中的方法--------通过配置生成页面。

3.实现步骤

3.1新建config配置文件

在menu文件夹下新建config配置文件:
在这里插入图片描述
menu/config/content.config.ts:

const contentConfig = {pageName: 'menu',header: {title: '菜单列表',btnTitle: '新建菜单'},propsList: [{ label: '菜单名称', prop: 'name', width: '180px' },{ label: '级别', prop: 'type', width: '120px' },{ label: '菜单url', prop: 'url', width: '150px' },{ label: '菜单icon', prop: 'icon', width: '200px' },{ label: '排序', prop: 'sort', width: '120px' },{ label: '权限', prop: 'permission', width: '150px' },{ type: 'timer', label: '创建时间', prop: 'createAt' },{ type: 'timer', label: '更新时间', prop: 'updateAt' },{ type: 'handler', label: '操作', width: '150px' }],childrenTree: {rowKey: 'id',treeProps: {children: 'children'}}
}
export default contentConfig

3.2封装组件

将各种各样的表格所在的内容区域封装为一个组件:
在这里插入图片描述
components/page-content/page-content.vue:

<template><div class="content"><div class="header"><h3 class="title">{{ contentConfig?.header?.title ?? '数据列表' }}</h3><el-button type="primary" @click="handleNewUserClick">{{ contentConfig?.header?.btnTitle ?? '新建数据' }}</el-button></div><div class="table"><el-table:data="pageList"borderstyle="width: 100%"v-bind="contentConfig.childrenTree"><template v-for="item in contentConfig.propsList" :key="item.prop"><template v-if="item.type === 'timer'"><el-table-column align="center" v-bind="item"><template #default="scope">{{ formatUTC(scope.row[item.prop]) }}</template></el-table-column></template><template v-else-if="item.type === 'handler'"><el-table-column align="center" v-bind="item"><template #default="scope"><el-buttonsize="small"icon="Edit"type="primary"text@click="handleEditBtnClick(scope.row)">编辑</el-button><el-buttonsize="small"icon="Delete"type="danger"text@click="handleDeleteBtnClick(scope.row.id)">删除</el-button></template></el-table-column></template><template v-else-if="item.type === 'custom'"><el-table-column align="center" v-bind="item"><template #default="scope"><slot:name="item.slotName"v-bind="scope":prop="item.prop"hName="why"></slot></template></el-table-column></template><template v-else><el-table-column align="center" v-bind="item" /></template></template></el-table></div><div class="pagination"><el-paginationv-model:current-page="currentPage"v-model:page-size="pageSize":page-sizes="[10, 20, 30]"layout="total, sizes, prev, pager, next, jumper":total="pageTotalCount"@size-change="handleSizeChange"@current-change="handleCurrentChange"/></div></div>
</template><script setup lang="ts">
...
interface IProps {contentConfig: {pageName: stringheader?: {title?: stringbtnTitle?: string}propsList: any[]childrenTree?: any}
}const props = defineProps<IProps>()
...
</script><style lang="less" scoped>
...
</style>

3.3使用组件

<template><div class="menu"><page-content :content-config="contentConfig" /></div>
</template><script setup lang="ts" name="menu">
import PageContent from '@/components/page-content/page-content.vue'
import contentConfig from './config/content.config'
</script><style scoped>
...
</style>

http://www.ppmy.cn/devtools/158481.html

相关文章

深入浅出学算法030-兔子繁殖

题目描述 有一种兔子&#xff0c;出生后一个月就可以长大&#xff0c;然后再过一个月一对长大的兔子就可以生育一对小兔子且以后每个月都能生育一对。现在&#xff0c;我们有一对刚出生的这种兔子&#xff0c;那么&#xff0c;n个月过后&#xff0c;我们会有多少对兔子呢&…

HTTP 请求头、响应头常见字段分析

目录 请求头AcceptAccept-EncodingUser-AgentConnectionCache-ControlHost 响应头Content-EncodingETagContent-TypeVaryx-business-use-case-usageAccess-Control-Allow-Originfacebook-api-versionStrict-Transport-SecurityPragmaCache-ControlExpiresx-fb-request-id 和 x-…

【C】链表算法题7 -- 环形链表||

leetcode链接https://leetcode.cn/problems/linked-list-cycle-ii/description/ 问题描述 给定一个链表的头节点 head &#xff0c;返回链表开始入环的第一个节点。 如果链表无环&#xff0c;则返回 null。如果链表中有某个节点&#xff0c;可以通过连续跟踪 next 指针再次到…

w206基于Spring Boot的农商对接系统的设计与实现

&#x1f64a;作者简介&#xff1a;多年一线开发工作经验&#xff0c;原创团队&#xff0c;分享技术代码帮助学生学习&#xff0c;独立完成自己的网站项目。 代码可以查看文章末尾⬇️联系方式获取&#xff0c;记得注明来意哦~&#x1f339;赠送计算机毕业设计600个选题excel文…

算法题(65):两数之和

审题&#xff1a; 需要我们在乱序数组中找到相加之和为target的两个数的下标&#xff0c;并返回 思路&#xff1a; 方法一&#xff1a;哈希表 我们创建哈希表&#xff0c;以数据值为键&#xff0c;以索引为值。 遍历数组nums&#xff0c;若可以在哈希表中找到键为target-nums[i…

串口通信梳理

常用的输入输出模式&#xff1a; 输入模式 浮空输入&#xff08;Floating Input&#xff09; 原理&#xff1a;引脚的电平状态完全由外部输入信号决定&#xff0c;内部没有上拉或下拉电阻与电源或地相连&#xff0c;引脚处于高阻抗状态。应用场景&#xff1a;适用于外部信号源…

MapReduce简单应用(三)——高级WordCount

目录 1. 高级WordCount1.1 IntWritable降序排列1.2 输入输出格式1.3 处理流程 2. 代码和结果2.1 pom.xml中依赖配置2.2 工具类util2.3 高级WordCount2.4 结果 参考 本文引用的Apache Hadoop源代码基于Apache许可证 2.0&#xff0c;详情请参阅 Apache许可证2.0。 1. 高级WordCo…

3.2 > Bash

概览 在上一节中我们了解了关于 Shell 的执行流程&#xff0c;知道了在 Linux 环境中一般有哪些常用的 Shell。而在本节中&#xff0c;将会学习到 Linux 中最常见的一个 Shell —— Bash&#xff0c;了解到 bash 的相关知识和用法。 本节目录 概览相关知识bash 命令提示符bas…