vue后台管理系统从0到1(5)

文章目录

  • vue后台管理系统从0到1(5)
    • 完善侧边栏
    • 修改bug
    • 渲染header导航栏

vue后台管理系统从0到1(5)

在这里插入图片描述
接上一期,我们需要完善我们的侧边狼

完善侧边栏

我们在 element 组件中可以看见,这一个侧边栏是符合我们的要求的
在这里插入图片描述
我们就使用这样一个侧边栏动态渲染我们的各个选项,但是目前没有接入后端接口,我们需要自己先定义静态侧边栏数据,然后在使用v-for动态渲染上去

在这里插入图片描述
这是我写好的侧边栏动态v-for渲染代码
在这里插入图片描述

这里是渲染数据和渲染方法

在这里插入图片描述

这里是加上的样式

以上代码,不懂的自己查gpt或者查一些ai

CommonAside.vue 完整代码

<template><el-aside width="200px"><el-menu @select="handleMenuSelect" background-color="#545c64" text-color="#fff"><h3>通用后台管理系统</h3><el-menu-itemv-for="item in noChildren":index="item.path":key="item.path"><i :class="item.icon"></i><span>{{ item.label }}</span></el-menu-item><el-sub-menuv-for="item in hasChildren":index="item.path":key="item.path"><template #title><i :class="item.icon"></i><span>{{ item.label }}</span></template><el-menu-itemv-for="subItem in item.children":index="subItem.path":key="subItem.path"><i :class="subItem.icon"></i><span>{{ subItem.label }}</span></el-menu-item></el-sub-menu></el-menu></el-aside>
</template><script setup>
import { ref, computed } from 'vue';
import { useRouter } from 'vue-router';const router = useRouter();
const list = ref([{ path: '/home', name: 'home', label: '首页', icon: 'el-icon-house', url: 'Home' },{ path: '/mall', name: 'mall', label: '商品管理', icon: 'el-icon-video-play', url: 'Mall' },{ path: '/user', name: 'user', label: '用户管理', icon: 'el-icon-user', url: 'User' },{path: '/other', label: '其他', icon: 'el-icon-location',children: [{ path: '/page1', name: 'page1', label: '页面1', icon: 'el-icon-setting', url: 'Page1' },{ path: '/page2', name: 'page2', label: '页2', icon: 'el-icon-setting', url: 'Page2' }]}
]);const noChildren = computed(() => list.value.filter(item => !item.children));
const hasChildren = computed(() => list.value.filter(item => item.children));const handleMenuSelect = (index) => {const item = list.value.find(item => item.path === index) ||list.value.flat().find(item => item.path === index);if (item) {router.push(item.path);}
};
</script><style lang="less" scoped>
.icons {width: 18px;height: 18px;margin-right: 5px;
}.el-menu{border-right: none;h3{line-height: 48px;color: #fff;text-align: center;}
}.el-aside{height: 10000px;background-color: #545c64;
}</style>

为了防止出错,重构 Main.vue 代码如下,不懂的gpt,我认为重要的是整个项目完成的流程
在这里插入图片描述

<script setup>
// 可以在这里添加组件的逻辑
import CommonAside from '@/components/CommonAside.vue'
</script><template><div class="common-layout"><el-container><el-aside width="200px"  class="aside-container"><!-- 侧边栏内容 --><common-aside></common-aside></el-aside><el-container><el-header class="el-header"><common-header></common-header></el-header><el-main class="right-main">main</el-main></el-container></el-container></div>
</template><style>.common-layout{width: 100%;height: 100%;margin: 0;padding: 0;overflow: hidden;
}
el-container{width: 100%;height: 100%;margin: 0;padding: 0;overflow: hidden;
}
.el-header{background-color: #333;
}
</style>

然后就是重新跑项目:
在这里插入图片描述
如果对于以上代码有问题可以私信我,我们的侧边栏就渲染完成了,这里有一个bug,就是我们的 icon 没有加载出来,我还没有发现问题在哪,如果你们发现了,可以私信我。
紧接着上文,我们的项目目前仍然存在侧边栏 icon 加载问题,我今天好好的看了一下代码,发现展示 icon 的地方代码出了问题

修改bug

在这里插入图片描述
这是我修改过的代码

我原本写的展示 icon 使用 标签,并且把 icon 的渲染写成了 class 属性里

重构 commonAside.vue 如下:

<template><el-aside width="200px"><el-menu @select="handleMenuSelect" background-color="#545c64" text-color="#fff"><h3>通用后台管理系统</h3><el-menu-itemv-for="item in noChildren":index="item.path":key="item.path"><component class="icons" :is="item.icon"></component><span>{{ item.label }}</span></el-menu-item><el-sub-menuv-for="item in hasChildren":index="item.path":key="item.path"><template #title><component class="icons" :is="item.icon"></component><span>{{ item.label }}</span></template><el-menu-itemv-for="subItem in item.children":index="subItem.path":key="subItem.path"><component class="icons" :is="subItem.icon"></component><span>{{ subItem.label }}</span></el-menu-item></el-sub-menu></el-menu></el-aside>
</template><script setup>
import { ref, computed } from 'vue';
import { useRouter } from 'vue-router';const router = useRouter();
const list = ref([{ path: '/home', name: 'home', label: '首页', icon: 'house', url: 'Home' },{ path: '/mall', name: 'mall', label: '商品管理', icon: 'video-play', url: 'Mall' },{ path: '/user', name: 'user', label: '用户管理', icon: 'user', url: 'User' },{path: '/other', label: '其他', icon: 'location',children: [{ path: '/page1', name: 'page1', label: '页面1', icon: 'setting', url: 'Page1' },{ path: '/page2', name: 'page2', label: '页2', icon: 'setting', url: 'Page2' }]}
]);const noChildren = computed(() => list.value.filter(item => !item.children));
const hasChildren = computed(() => list.value.filter(item => item.children));const handleMenuSelect = (index) => {const item = list.value.find(item => item.path === index) ||list.value.flat().find(item => item.path === index);if (item) {router.push(item.path);}
};
</script><style lang="less" scoped>
.icons {width: 18px;height: 18px;margin-right: 5px;
}.el-menu{border-right: none;h3{line-height: 48px;color: #fff;text-align: center;}
}.el-aside{height: 10000px;background-color: #545c64;
}</style>

渲染header导航栏

然后我们接着渲染我们的 header 导航栏部分,目标是渲染成这样
在这里插入图片描述
那么第一步分析界面布局

可以得出以下两个部分,也是我们需要分开写的两个部件

首先,使用一个 header 把整体包起来

  <div class="header"></div>

然后我们把导航栏分成左右两部分,左边有图标和首页字体,右边是用户头像

  <div class="header"><div class="l-content"></div><div class="r-content"></div></div>

然后我们具体实现左右两边的东西

  <div class="header"><div class="l-content">//图标<el-button size="small"><component class="icons" is="menu"></component></el-button>//面包屑字体<el-breadcrumb separator="/" class="bread"><el-breadcrumb-item :to="{path:'/'}">首页</el-breadcrumb-item></el-breadcrumb></div><div class="r-content">//用户头像<el-dropdown><span class="el-dropdown-link"><img :src="getImageUrl(user)" class="user"/></span><template #dropdown>//单击头像退出按钮<el-dropdown-menu><el-dropdown-item>个人中心</el-dropdown-item><el-dropdown-item>退出</el-dropdown-item></el-dropdown-menu></template></el-dropdown></div></div>

然后我们加入样式

<style lang="less" scoped>
.header {display: flex;justify-content: space-between;align-items: center;width: 100%;height: 100%;background-color: #333;}.icons {width: 20px;height: 20px;
}.l-content {display: flex;align-items: center;.el-button{margin-right: 20px;}}.r-content  {.user{width: 40px;height: 40px;border-radius: 50%;}
}/* 注意::deep() 是一个 Vue.js 中的作用域穿透伪元素,用于在 scoped CSS 中访问子组件的样式。但它不是标准的 CSS 语法,且在新版本的 Vue.js 中可能已经被废弃或替换。如果这段代码是在 Vue.js 项目中使用的,请确保你的项目支持这种语法。此外,由于选择器中包含特殊字符(如点号和括号),你可能需要对其进行适当的转义或使用其他方法来实现相同的效果。但在这里,为了保持原始信息的完整性,我保留了这段代码的原样。 */
:deep(.bread span) {color: #fff !important;cursor: pointer !important;
}</style>

再加入渲染数据的代码

<script setup>
import {ref, computed} from 'vue';
import {useRouter} from 'vue-router';const router = useRouter();
const list = ref([{path: '/home', name: 'home', label: '首页', icon: 'el-icon-house', url: 'Home'},{path: '/mall', name: 'mall', label: '商品管理', icon: 'el-icon-video-play', url: 'Mall'},{path: '/user', name: 'user', label: '用户管理', icon: 'el-icon-user', url: 'User'},{path: '/other', label: '其他', icon: 'el-icon-location',children: [{path: '/page1', name: 'page1', label: '页面1', icon: 'el-icon-setting', url: 'Page1'},{path: '/page2', name: 'page2', label: '页2', icon: 'el-icon-setting', url: 'Page2'}]}
]);const getImageUrl = (user) => {return new URL(`../assets/images/${user}.png`, import.meta.url).href;
};
</script>

最后整合代码:
CommonHeader.vue代码:

<template><div class="header"><div class="l-content"><el-button size="small"><component class="icons" is="menu"></component></el-button><el-breadcrumb separator="/" class="bread"><el-breadcrumb-item :to="{path:'/'}">首页</el-breadcrumb-item></el-breadcrumb></div><div class="r-content"><el-dropdown><span class="el-dropdown-link"><img :src="getImageUrl(user)" class="user"/></span><template #dropdown><el-dropdown-menu><el-dropdown-item>个人中心</el-dropdown-item><el-dropdown-item>退出</el-dropdown-item></el-dropdown-menu></template></el-dropdown></div></div></template><script setup>
import {ref, computed} from 'vue';
import {useRouter} from 'vue-router';const router = useRouter();
const list = ref([{path: '/home', name: 'home', label: '首页', icon: 'el-icon-house', url: 'Home'},{path: '/mall', name: 'mall', label: '商品管理', icon: 'el-icon-video-play', url: 'Mall'},{path: '/user', name: 'user', label: '用户管理', icon: 'el-icon-user', url: 'User'},{path: '/other', label: '其他', icon: 'el-icon-location',children: [{path: '/page1', name: 'page1', label: '页面1', icon: 'el-icon-setting', url: 'Page1'},{path: '/page2', name: 'page2', label: '页2', icon: 'el-icon-setting', url: 'Page2'}]}
]);const getImageUrl = (user) => {return new URL(`../assets/images/${user}.png`, import.meta.url).href;
};
</script><style lang="less" scoped>
.header {display: flex;justify-content: space-between;align-items: center;width: 100%;height: 100%;background-color: #333;}.icons {width: 20px;height: 20px;
}.l-content {display: flex;align-items: center;.el-button{margin-right: 20px;}}.r-content  {.user{width: 40px;height: 40px;border-radius: 50%;}
}/* 注意::deep() 是一个 Vue.js 中的作用域穿透伪元素,用于在 scoped CSS 中访问子组件的样式。但它不是标准的 CSS 语法,且在新版本的 Vue.js 中可能已经被废弃或替换。如果这段代码是在 Vue.js 项目中使用的,请确保你的项目支持这种语法。此外,由于选择器中包含特殊字符(如点号和括号),你可能需要对其进行适当的转义或使用其他方法来实现相同的效果。但在这里,为了保持原始信息的完整性,我保留了这段代码的原样。 */
:deep(.bread span) {color: #fff !important;cursor: pointer !important;
}</style>

然后,我们启动项目,查看如下:
在这里插入图片描述
这样一个新的组件就被我们写好了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/pingmian/56716.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Linux驱动开发——platform平台总线

bus_type 一、主要作用 设备管理 bus_type负责管理连接在特定总线上的设备。它维护一个设备链表&#xff0c;其中包含了所有注册到该总线上的设备。通过这个链表&#xff0c;内核可以方便地遍历和管理连接在该总线上的设备。例如&#xff0c;对于 PCI 总线&#xff0c;bus_typ…

无人机之视觉技术篇

一、视觉传感器的类型 摄像头&#xff1a; 最常见的视觉传感器&#xff0c;能够捕捉可见光图像和视频。 通过单目、双目或多目摄像头的组合&#xff0c;无人机能够实现立体视觉&#xff0c;从而估算距离、深度&#xff0c;并进行物体识别和追踪。 红外传感器&#xff1a; …

银行卡二三四要素验证接口-在线银行卡二三四要素验证-银行卡二三四要素验证API

接口简介&#xff1a;全面覆盖&#xff0c;支持所有带银联标识的银行卡; 高准确性-验证结果实时返回&#xff0c;准确率达99%; 银行卡二要素若是手机号卡号&#xff0c;不支持工商和农商行 接口地址&#xff1a;https://www.wapi.cn/api_detail/102/235.html 在线核验&#xff…

【汇编语言】寄存器(内存访问)(七)—— CPU提供的栈机制

文章目录 前言1. CPU提供的栈机制2. push指令3. 问题4. 问题的分析与解答5. pop指令结语 前言 &#x1f4cc; 汇编语言是很多相关课程&#xff08;如数据结构、操作系统、微机原理&#xff09;的重要基础。但仅仅从课程的角度出发就太片面了&#xff0c;其实学习汇编语言可以深…

基于Java的茶叶商城设计与实现(源码+定制+开发)茶叶电商系统开发、茶叶电商平台开发、茶叶在线销售平台设计与开发

博主介绍&#xff1a; ✌我是阿龙&#xff0c;一名专注于Java技术领域的程序员&#xff0c;全网拥有10W粉丝。作为CSDN特邀作者、博客专家、新星计划导师&#xff0c;我在计算机毕业设计开发方面积累了丰富的经验。同时&#xff0c;我也是掘金、华为云、阿里云、InfoQ等平台…

英伟达开源最新大模型Nemotron 70B后,只有OpenAI o1一个对手了

来源 | 机器之心 今天&#xff0c;英伟达又开源了一个性能超级强大的模型 —— Llama-3.1-Nemotron-70B-Instruct&#xff0c;它击败了 OpenAI 的 GPT-4o 和 Anthropic 的 Claude-3.5 Sonnet 等多个开闭源模型。 从命名来看&#xff0c;显然 Llama-3.1-Nemotron-70B-Instruct …

2024.09.27校招 实习 内推 面经

&#x1f6f0;️ &#xff1a;neituijunsir 交* 流*裙 &#xff0c;内推/实习/校招汇总表格 1、校招丨小米2024届补录招聘正式回归&#xff08;内推&#xff09; 校招丨小米2024届补录招聘正式回归&#xff08;内推&#xff09; 2、校招丨移动研究院2025届校园招聘全面启…

DE项目整里

系列文章目录 文章目录 系列文章目录一、Airflow-AWS ETL项目二、snowflake ETL项目三、AWS DE的快速入门课程 一、Airflow-AWS ETL项目 项目作者&#xff1a;tuplespectra&#xff08;主要是AWS&#xff0c;EC2&#xff0c;GLUE 的项目&#xff09;项目地址&#xff1a; htt…

MySQL-15.DQL-排序查询

一.DQL-排序查询 -- 排序查询 -- 1.根据入职时间&#xff0c;对员工进行升序排序 select * from tb_emp order by entrydate asc ;-- 2.根据入职时间&#xff0c;对员工进行降序排序 select * from tb_emp order by entrydate desc ;-- 3.根据 入职时间 对公司员工进行 升序排序…

selenium自动化关闭

该段代码属于固定代码&#xff0c;直接誊抄即可使用&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01;&#xff01; !!!!!建议整理到小本本上&#xff01;&#xff01;&#xff01; #设置关闭selenium的自动化特性和拓展&#xff0c;防止被网站检测…

【MogDB】MogDB5.2.0重磅发布第三篇-支持astore下的rowid

一、背景 从ORACLE迁移到国产数据库&#xff0c;经常会遇到rowid的兼容性问题&#xff0c;可能是不支持rowid这个关键字&#xff0c;也可能是rowid数据类型或rowid的行为和oracle不一样。 rowid特征&#xff1a; rowid是表上的一个伪列rowid字段在数据字典中不存在select * …

scala 高阶函数(2)上

学习目录 一.reduce reduce的含义 idea实例 二.reduceLeft-reduceRight reduceLeft-reduceRight的含义 idea实例 练习&#xff1a;求最值

word建立目录以及修改页码

1、为word建立新的目录 &#xff08;1&#xff09;选中word中的标题设置为第几级标题&#xff0c;将所有的标题均设置完成。最后可以鼠标右击标题&#xff0c;对不同的标题字体大小等进行设置。右击-->修改-->格式-->段落 &#xff08;2&#xff09;在word中插入新的…

【多模态大模型】 端侧多模态模型 Qwen2-VL-2B-Instruct

【多模态大模型】 端侧多模态模型 Qwen2-VL-2B-Instruct Qwen2-VL-2B-Instruct 模型介绍模型测评运行环境安装运行模型Image Resolution for performance boosttwo methods for fine-grained control over the image size input to the model: 下载开源协议参考 Qwen2-VL-2B-In…

sql之update语句

SQL&#xff08;Structured Query Language&#xff09;是一种用于管理和操作关系数据库的强大语言。UPDATE语句是SQL中用于修改数据库中已存在记录的一种方法。以下是一些经典的UPDATE语句案例&#xff1a; 1.更新特定行的列值&#xff1a; UPDATE employees SET salary sa…

专题十二_floodfill(洪水灌溉)算法_算法专题详细总结

目录 1. 图像渲染&#xff08;medium&#xff09; 解析&#xff1a; 函数头&#xff1a; 函数体&#xff1a;固定模板 设置全局变量&#xff1a; 总结&#xff1a; 2. 岛屿数量&#xff08;medium&#xff09; 解析&#xff1a; 注意&#xff1a; 总结&#xff1a; …

补题:B. Hemose Shopping

传送门&#xff1a;Problem - B - Codeforces 题意&#xff1a;给定由 n 个元素组成的数组&#xff0c;现给定操作 选取索引 i j &#xff0c;如果 abs( i - j ) > x 就可以交换 swap( a[i] , a[j] )&#xff0c;可以进行任意次操作&#xff0c;如果操作后的数组是不递减的…

利用由 Search AI 提供支持的自动导入功能加速 Elastic Observability 中的日志分析

作者&#xff1a;来自 Elastic Bahubali Shetti 通过自动化自定义数据集成&#xff0c;以创纪录的速度将日志迁移到 AI 驱动的日志分析。 Elastic 正在通过自动提取自定义日志来加速采用 AI 驱动的日志分析&#xff08;AI-driven log analytics&#xff09;&#xff0c;随着基…

时间序列预测(六)——循环神经网络(RNN)

目录 一、RNN的基本原理 1、正向传播&#xff08;Forward Pass&#xff09;&#xff1a; 2、计算损失&#xff08;Loss Calculation&#xff09; 3、反向传播——反向传播通过时间&#xff08;Backpropagation Through Time&#xff0c;BPTT&#xff09; 4、梯度更新&…

Flink时间语义和时间窗口

前言 在实际的流计算业务场景中&#xff0c;我们会发现&#xff0c;数据和数据的计算往往都和时间具有相关性。 举几个例子&#xff1a; 直播间右上角通常会显示观看直播的人数&#xff0c;并且这个数字每隔一段时间就会更新一次&#xff0c;比如10秒。电商平台的商品列表&a…