使用AI一步一步实现若依前端(4)

news/2025/3/11 13:35:28/

功能4:首页使用Layout布局

功能3:点击登录按钮实现页面跳转
功能2:静态登录界面
功能1:创建前端项目

前言

Layout布局的效果。在侧边栏点击不同菜单,只有红框里的内容会对应改变。
整个页面是父路由的component渲染,红框是子路由的component渲染。
在这里插入图片描述

一.操作步骤

1.使用AI生成Layout页面

在这里插入图片描述

2.新建文件

src/
├─ layout/
│  ├─ components/
│  │  ├─ Navbar.vue
│  │  ├─ Sidebar.vue
│  │  └─ AppMain.vue
│  ├─ index.vue

为了保持跟若依基本一致的文件目录。按照上面的路径新建文件,然后将AI生成的内容复制到对应的文件里。

1.Sidebar组件 (Sidebar.vue)
<script setup>
import { RouterLink } from 'vue-router'
import {ElMenu,ElMenuItem,ElSubMenu,ElIcon
} from 'element-plus'
import { Document, Setting } from '@element-plus/icons-vue'
import { useRoute } from 'vue-router'const route = useRoute()
</script><template><el-menu:default-active="route.path"class="h-full"routerbackground-color="#304156"text-color="#bfcbd9"active-text-color="#409EFF"><el-menu-item index="/"><el-icon><Document /></el-icon><span>首页</span></el-menu-item><el-sub-menu index="/about"><template #title><el-icon><Setting /></el-icon><span>关于</span></template><el-menu-item index="/about">关于我们</el-menu-item></el-sub-menu></el-menu>
</template><style scoped>
.el-menu {border-right: none;
}
</style>
2.Navbar组件 (Navbar.vue)
<script setup>
import { ElHeader, ElBreadcrumb, ElBreadcrumbItem } from 'element-plus'const breadcrumbItems = [{ title: '首页', path: '/' },{ title: '关于', path: '/about' }
]
</script><template><el-header class="bg-white border-b flex items-center"><el-breadcrumb separator="/"><el-breadcrumb-itemv-for="item in breadcrumbItems":key="item.path":to="item.path">{{ item.title }}</el-breadcrumb-item></el-breadcrumb></el-header>
</template>
3.AppMain组件 (AppMain.vue)
<script setup>
import { ElMain } from 'element-plus'
</script><template><el-main><router-view v-slot="{ Component }"><transition name="fade-transform" mode="out-in"><component :is="Component" /></transition></router-view></el-main>
</template><style scoped>
.el-main {padding: 20px;background-color: #f0f2f5;
}
</style>
4.布局组件 (layout/index.vue)

AI生成的代码,文件目录结构有可能跟我们的不一样,要注意修改下面的import组件的位置。

<script setup>
import { ElContainer, ElAside } from 'element-plus'
import Sidebar from './components/Sidebar.vue'
import Navbar from './components/Navbar.vue'
import AppMain from './components/AppMain.vue'
</script><template><el-container class="h-screen"><el-aside width="200px"><Sidebar /></el-aside><el-container><el-header height="48px"><Navbar /></el-header><AppMain /></el-container></el-container>
</template><style>
.el-header {--el-header-padding: 0;height: auto;
}
</style>

3.修改路由配置(src/router/index.js)

将路由记录修改为嵌套路由,layout页面为父级布局组件,子路由的组件就是具体的页面。

import Layout from '@/layout/index.vue'{path: '/',component: Layout,redirect: '/index',children: [{path: 'index',component: () => import('@/views/index.vue'),}]}

二.功能验证

启动项目,浏览器输入http://localhost:5173
在这里插入图片描述
基本结构是有了,就是页面看起来很
项目一开始,最重要的一定是先有功能
然后才有性能,优化,美化…(99+)

三.知识点拓展

1. 嵌套路由实现

// 路由配置核心代码
{path: '/',component: Layout,        // 父级布局组件children: [               // 嵌套子路由{path: 'index',        // 实际路径 /indexcomponent: Home       // 子页面组件}]
}

父子路由关系:父路由负责整体布局,子路由在指定区域渲染
路径继承:子路由路径会自动继承父级路径,形成完整路径

2. 动态路由匹配

<!-- Sidebar中的路由匹配 -->
<el-menu-item index="/about">
// 通过useRoute获取当前路径
const route = useRoute()

路由激活状态:通过对比当前路径实现菜单高亮
响应式更新:当路由变化时,相关组件自动更新

3. 命名视图

// 多视图布局配置
{path: '/',components: {default: Layout,sidebar: CustomSidebar}
}

• 允许在同一个页面中定义多个路由出口
• 通过<router-view name="sidebar">指定渲染位置

4. 过渡动画

<!-- AppMain中的过渡效果 -->
<transition name="fade-transform" mode="out-in"><component :is="Component" />
</transition>

动画类型
• fade-transform:淡入淡出结合位移效果
• mode=“out-in”:保证旧组件先退出,新组件再进入
组件复用:通过<component>实现动态组件渲染

5. 响应式布局技巧

/* 全屏布局实现 */
.h-screen {height: 100vh;
}
.flex {display: flex;
}

视窗单位:vh/vw实现自适应布局
Flex布局:实现灵活的内容排列
层叠上下文:z-index管理侧边栏与内容层级

四.思考

1.一点不会前端,也能依靠AI完成整个项目吗?

AI可以帮我们写出了90%的代码,剩下10%,还需要程序员根据实际的功能需求,参考ElementPlus官网,vue官网,配合浏览器的开发者工具等。在遇到问题时,解决问题。


http://www.ppmy.cn/news/1578358.html

相关文章

VTK知识学习(46)- 体绘制(一)

1、前言 前面所采用的渲染技术都是几何渲染&#xff0c;即通过绘制几何图元(顶点、线段、面片等)来渲染数据&#xff0c;例如&#xff0c;绘制图像需要在空间中建立一个四边形图元&#xff0c;然后以纹理映射的方式将图像贴图到该图元上进行渲染;而三维模型的绘制通常会分解为一…

Python 编程题 第八节:字符串变形、压缩字符串、三个数的最大乘积、判定字符是否唯一、IP地址转换

字符串变形 swapcase()方法将字符串大小写转换&#xff1b;split()方法将字符串以括号内的符号分隔并以列表形式返回 sinput() ls.split(" ") ll[::-1] s"" for i in l:ai.swapcase()sas" " print(s[0:len(s)-1]) 压缩字符串 很巧妙的方法 …

Golang学习笔记_48——中介者模式

Golang学习笔记_45——备忘录模式 Golang学习笔记_46——状态模式 Golang学习笔记_47——访问者模式 文章目录 一、核心概念1. 定义2. 解决的问题3. 核心角色4. 类图 二、特点分析三、适用场景1. 航空管制系统2. 分布式交易系统3. GUI组件交互 四、Go语言实现示例完整实现代码执…

界面组件DevExpress WPF中文教程:Grid - 如何创建栏(Bands)?

DevExpress WPF拥有120个控件和库&#xff0c;将帮助您交付满足甚至超出企业需求的高性能业务应用程序。通过DevExpress WPF能创建有着强大互动功能的XAML基础应用程序&#xff0c;这些应用程序专注于当代客户的需求和构建未来新一代支持触摸的解决方案。 无论是Office办公软件…

DINOv2:无监督学习强大的视觉特征

Paper Title: DINOv2: Learning Robust Visual Features without Supervision 论文发布于CVPR2023 DINOv2是一种无监督学习的计算机视觉模型,该模型在处理多种视觉任务时,不需要进行微调便能提供优异的性能。 上图展示了 PCA(主成分分析)方法在图像补丁上的应用。具体来说…

python中如何把dataframe转换为列表及其性能比较

在Python中&#xff0c;将DataFrame转换为列表常用的方法有以下几种&#xff1a; ### 1. 使用values属性 先通过values属性将DataFrame转换为NumPy数组&#xff0c;然后再调用tolist()方法将数组转换为列表。这是一种简单直接的方式&#xff0c;适用于快速将整个DataFrame转换…

三维仿射变换矩阵

三维仿射变换矩阵 平移变换缩放变换旋转变换绕x、y、z单个轴旋转的变换绕任意轴旋转 三维仿射变换矩阵有 3 4 、 4 4 3\times4、4\times4 34、44两种写法&#xff0c;都是施加到三维点的齐次式上&#xff0c; 4 4 4\times4 44的仿射变换矩阵是在 3 4 3\times4 34的矩阵后追…

Node.js和Vue CLI 安装指南(Windows 系统)

Node.js 与 Vue CLI 安装指南&#xff08;Windows 系统&#xff09; 一、Node.js 安装步骤 1. 安装包获取 官网下载&#xff1a;Node.js 官网推荐选择 LTS 版本&#xff08;长期支持版&#xff09;双击运行安装包&#xff1a; 2. 安装向导配置 点击 "Next" 进入…