要快速搭建一个基于 Vue3 与 ElementPlus 的后台管理系统基础框架可以遵循以下步骤。整个过程将涵盖项目初始化、ElementPlus 集成、基础布局搭建、路由配置以及动态菜单实现等核心环节并辅以详细的代码示例。1. 项目初始化与环境检查首先确保你的开发环境已准备就绪。推荐使用 Vite 作为构建工具因为它为 Vue3 提供了极速的开发体验 。步骤检查 Node.js 版本建议使用 Node.js 16 或更高版本。node -v使用 Vite 创建项目npm create vuelatest my-vue-app # 或 yarn create vuelatest my-vue-app在创建过程中可以根据提示选择需要的特性如 TypeScript、Router 等。进入项目并安装依赖cd my-vue-app npm install启动开发服务器npm run dev访问http://localhost:5173确认项目运行正常 。2. 集成 ElementPlus 组件库ElementPlus 是基于 Vue 3 的流行组件库能极大提升后台管理系统的开发效率 。安装与全局引入安装 ElementPlusnpm install element-plus --save在main.js或main.ts中全局引入// main.js / main.ts import { createApp } from vue import ElementPlus from element-plus import element-plus/dist/index.css // 引入样式文件 import App from ./App.vue import router from ./router const app createApp(App) app.use(ElementPlus) app.use(router) app.mount(#app)全局引入后即可在项目的任何组件中使用 ElementPlus 的组件 。3. 搭建基础页面布局后台管理系统通常采用经典的头部-侧边栏-主内容区的布局。ElementPlus 的el-container系列组件非常适合构建此类布局 。示例布局组件Layout.vue!-- src/views/Layout.vue -- template div classcommon-layout el-container !-- 顶部 Header -- el-header classcommon-header flex-float div classflex img classlogo src/assets/logo.png altLogo / h1 classtitle后台管理系统/h1 /div el-button typedanger clickhandleLogout退出/el-button /el-header el-container !-- 左侧 Aside 导航菜单 -- el-aside classcommon-aside width200px !-- 导航菜单将在下一步实现 -- side-menu / /el-aside !-- 右侧 Main 内容区 -- el-main router-view / !-- 路由视图用于渲染子页面 -- /el-main /el-container /el-container /div /template script setup import SideMenu from /components/SideMenu.vue const handleLogout () { // 退出登录逻辑 console.log(退出登录) } /script style scoped .el-container { height: 100vh; overflow: hidden; } .common-header { background-color: rgb(63, 67, 72); display: flex; justify-content: space-between; align-items: center; } .common-aside { background-color: rgb(48, 55, 65); } .logo { width: 60px; } .title { color: #fff; margin-left: 10px; } .flex-float { display: flex; justify-content: space-between; align-items: center; } .flex { display: flex; align-items: center; } /style此布局创建了一个包含顶部栏、侧边栏和主内容区的容器侧边栏预留了导航菜单的位置 。4. 实现动态导航菜单动态菜单能根据用户权限或配置灵活显示是后台管理系统的核心功能之一。我们可以结合 Vue Router 和 ElementPlus 的el-menu组件来实现 。步骤与示例定义路由配置在router/index.js中配置路由特别是嵌套路由子路由以对应菜单项。// src/router/index.js import { createRouter, createWebHistory } from vue-router import Layout from /views/Layout.vue const routes [ { path: /, component: Layout, redirect: /dashboard, // 默认重定向到仪表盘 children: [ // 嵌套路由对应侧边栏菜单项 { path: dashboard, name: Dashboard, component: () import(/views/Dashboard.vue), meta: { title: 仪表盘, icon: Odometer } }, { path: user, name: User, component: () import(/views/system/User.vue), meta: { title: 用户管理, icon: User } }, { path: role, name: Role, component: () import(/views/system/Role.vue), meta: { title: 角色管理, icon: Lock } } // ... 可以继续添加更多路由 ] }, { path: /login, name: Login, component: () import(/views/Login.vue) } ] const router createRouter({ history: createWebHistory(), routes }) export default router创建动态菜单组件创建一个SideMenu.vue组件根据路由配置动态生成菜单。!-- src/components/SideMenu.vue -- template el-menu :default-activeactiveMenu classel-menu-vertical-demo background-colorrgb(48, 55, 65) text-color#fff active-text-color#ffd04b :routertrue !-- 启用 vue-router 模式点击菜单进行路由跳转 -- :collapseisCollapse template v-forroute in menuRoutes :keyroute.path !-- 有子菜单的情况 -- el-sub-menu v-ifroute.children route.children.length 0 :indexroute.path template #title el-icon v-ifroute.meta.icon component :isroute.meta.icon / /el-icon span{{ route.meta.title }}/span /template el-menu-item v-forchild in route.children :keychild.path :indexchild.path {{ child.meta.title }} /el-menu-item /el-sub-menu !-- 没有子菜单直接是菜单项 -- el-menu-item v-else :indexroute.path el-icon v-ifroute.meta.icon component :isroute.meta.icon / /el-icon span{{ route.meta.title }}/span /el-menu-item /template /el-menu /template script setup import { ref, computed } from vue import { useRoute } from vue-router import { useRouter } from vue-router const route useRoute() const router useRouter() const isCollapse ref(false) // 控制菜单折叠状态 // 从路由配置中过滤出需要显示在菜单中的路由 const menuRoutes computed(() { // 这里假设根路由Layout只有一个且其children是菜单项 const layoutRoute router.options.routes.find(r r.path /) return layoutRoute ? layoutRoute.children : [] }) // 计算当前激活的菜单用于高亮 const activeMenu computed(() { return route.path }) /script style scoped .el-menu-vertical-demo:not(.el-menu--collapse) { width: 200px; min-height: 400px; } /style此组件通过遍历路由配置动态生成菜单结构并利用:routertrue属性将菜单点击与路由跳转绑定 。5. 核心功能模块与优化建议完成基础框架后可以进一步集成以下模块以完善系统模块描述关键技术/组件用户登录/权限实现登录验证、路由守卫、动态路由加载。Vue Router 导航守卫、JWT、状态管理 (Pinia/Vuex)主题切换支持亮色/暗色主题或自定义主题。ElementPlus 自定义主题、CSS 变量数据表格与表单展示和操作数据的主要界面。el-table,el-form,el-pagination图标管理使用 SVG 图标提升灵活性和性能。封装SvgIcon组件使用h()渲染函数代码生成器根据模型自动生成 CRUD 代码提升开发效率。基于模板的代码生成示例一个简单的用户列表页面User.vue!-- src/views/system/User.vue -- template div el-card template #header div classcard-header span用户列表/span el-button typeprimary clickhandleAdd新增用户/el-button /div /template el-table :datatableData stylewidth: 100% el-table-column propdate label日期 width180 / el-table-column propname label姓名 width180 / el-table-column propaddress label地址 / el-table-column label操作 width180 template #defaultscope el-button sizesmall clickhandleEdit(scope.$index, scope.row) 编辑/el-button el-button sizesmall typedanger clickhandleDelete(scope.$index, scope.row) 删除/el-button /template /el-table-column /el-table el-pagination classpagination v-model:current-pagecurrentPage :page-size10 layouttotal, prev, pager, next, jumper :total100 current-changehandleCurrentChange / /el-card /div /template script setup import { ref } from vue const tableData ref([ { date: 2016-05-03, name: 张三, address: 北京市海淀区 }, // ... 更多数据 ]) const currentPage ref(1) const handleAdd () { console.log(新增用户) } const handleEdit (index, row) { console.log(编辑, index, row) } const handleDelete (index, row) { console.log(删除, index, row) } const handleCurrentChange (val) { console.log(当前页: ${val}) // 这里应发起请求获取对应页的数据 } /script style scoped .card-header { display: flex; justify-content: space-between; align-items: center; } .pagination { margin-top: 20px; justify-content: flex-end; } /style通过以上步骤你已经成功搭建了一个具备基础布局、动态路由菜单和基本功能模块的 Vue3 ElementPlus 后台管理系统框架。这个框架结构清晰、易于扩展可以作为大多数中后台项目的起点。后续可以根据具体业务需求在此基础上集成状态管理、API 封装、权限控制等更多高级功能 。参考来源Vue3.0商店后台管理系统项目实战-vue3搭配Element Plus框架使用Vue3实战二、搭建Vue3ElementPlus项目教程基于Vue3 Element Plus 的后台管理系统详细教程Vue3ElementPlus搭建后台管理系统模板Vue3教程开发一个 Vue 3 element-plus 的后台管理系统[vue3] 使用ElementPlus页面布局搭建架子
【Vue】Vue3+ElementPlus快速搭建后台管理框架
发布时间:2026/7/17 1:29:53
要快速搭建一个基于 Vue3 与 ElementPlus 的后台管理系统基础框架可以遵循以下步骤。整个过程将涵盖项目初始化、ElementPlus 集成、基础布局搭建、路由配置以及动态菜单实现等核心环节并辅以详细的代码示例。1. 项目初始化与环境检查首先确保你的开发环境已准备就绪。推荐使用 Vite 作为构建工具因为它为 Vue3 提供了极速的开发体验 。步骤检查 Node.js 版本建议使用 Node.js 16 或更高版本。node -v使用 Vite 创建项目npm create vuelatest my-vue-app # 或 yarn create vuelatest my-vue-app在创建过程中可以根据提示选择需要的特性如 TypeScript、Router 等。进入项目并安装依赖cd my-vue-app npm install启动开发服务器npm run dev访问http://localhost:5173确认项目运行正常 。2. 集成 ElementPlus 组件库ElementPlus 是基于 Vue 3 的流行组件库能极大提升后台管理系统的开发效率 。安装与全局引入安装 ElementPlusnpm install element-plus --save在main.js或main.ts中全局引入// main.js / main.ts import { createApp } from vue import ElementPlus from element-plus import element-plus/dist/index.css // 引入样式文件 import App from ./App.vue import router from ./router const app createApp(App) app.use(ElementPlus) app.use(router) app.mount(#app)全局引入后即可在项目的任何组件中使用 ElementPlus 的组件 。3. 搭建基础页面布局后台管理系统通常采用经典的头部-侧边栏-主内容区的布局。ElementPlus 的el-container系列组件非常适合构建此类布局 。示例布局组件Layout.vue!-- src/views/Layout.vue -- template div classcommon-layout el-container !-- 顶部 Header -- el-header classcommon-header flex-float div classflex img classlogo src/assets/logo.png altLogo / h1 classtitle后台管理系统/h1 /div el-button typedanger clickhandleLogout退出/el-button /el-header el-container !-- 左侧 Aside 导航菜单 -- el-aside classcommon-aside width200px !-- 导航菜单将在下一步实现 -- side-menu / /el-aside !-- 右侧 Main 内容区 -- el-main router-view / !-- 路由视图用于渲染子页面 -- /el-main /el-container /el-container /div /template script setup import SideMenu from /components/SideMenu.vue const handleLogout () { // 退出登录逻辑 console.log(退出登录) } /script style scoped .el-container { height: 100vh; overflow: hidden; } .common-header { background-color: rgb(63, 67, 72); display: flex; justify-content: space-between; align-items: center; } .common-aside { background-color: rgb(48, 55, 65); } .logo { width: 60px; } .title { color: #fff; margin-left: 10px; } .flex-float { display: flex; justify-content: space-between; align-items: center; } .flex { display: flex; align-items: center; } /style此布局创建了一个包含顶部栏、侧边栏和主内容区的容器侧边栏预留了导航菜单的位置 。4. 实现动态导航菜单动态菜单能根据用户权限或配置灵活显示是后台管理系统的核心功能之一。我们可以结合 Vue Router 和 ElementPlus 的el-menu组件来实现 。步骤与示例定义路由配置在router/index.js中配置路由特别是嵌套路由子路由以对应菜单项。// src/router/index.js import { createRouter, createWebHistory } from vue-router import Layout from /views/Layout.vue const routes [ { path: /, component: Layout, redirect: /dashboard, // 默认重定向到仪表盘 children: [ // 嵌套路由对应侧边栏菜单项 { path: dashboard, name: Dashboard, component: () import(/views/Dashboard.vue), meta: { title: 仪表盘, icon: Odometer } }, { path: user, name: User, component: () import(/views/system/User.vue), meta: { title: 用户管理, icon: User } }, { path: role, name: Role, component: () import(/views/system/Role.vue), meta: { title: 角色管理, icon: Lock } } // ... 可以继续添加更多路由 ] }, { path: /login, name: Login, component: () import(/views/Login.vue) } ] const router createRouter({ history: createWebHistory(), routes }) export default router创建动态菜单组件创建一个SideMenu.vue组件根据路由配置动态生成菜单。!-- src/components/SideMenu.vue -- template el-menu :default-activeactiveMenu classel-menu-vertical-demo background-colorrgb(48, 55, 65) text-color#fff active-text-color#ffd04b :routertrue !-- 启用 vue-router 模式点击菜单进行路由跳转 -- :collapseisCollapse template v-forroute in menuRoutes :keyroute.path !-- 有子菜单的情况 -- el-sub-menu v-ifroute.children route.children.length 0 :indexroute.path template #title el-icon v-ifroute.meta.icon component :isroute.meta.icon / /el-icon span{{ route.meta.title }}/span /template el-menu-item v-forchild in route.children :keychild.path :indexchild.path {{ child.meta.title }} /el-menu-item /el-sub-menu !-- 没有子菜单直接是菜单项 -- el-menu-item v-else :indexroute.path el-icon v-ifroute.meta.icon component :isroute.meta.icon / /el-icon span{{ route.meta.title }}/span /el-menu-item /template /el-menu /template script setup import { ref, computed } from vue import { useRoute } from vue-router import { useRouter } from vue-router const route useRoute() const router useRouter() const isCollapse ref(false) // 控制菜单折叠状态 // 从路由配置中过滤出需要显示在菜单中的路由 const menuRoutes computed(() { // 这里假设根路由Layout只有一个且其children是菜单项 const layoutRoute router.options.routes.find(r r.path /) return layoutRoute ? layoutRoute.children : [] }) // 计算当前激活的菜单用于高亮 const activeMenu computed(() { return route.path }) /script style scoped .el-menu-vertical-demo:not(.el-menu--collapse) { width: 200px; min-height: 400px; } /style此组件通过遍历路由配置动态生成菜单结构并利用:routertrue属性将菜单点击与路由跳转绑定 。5. 核心功能模块与优化建议完成基础框架后可以进一步集成以下模块以完善系统模块描述关键技术/组件用户登录/权限实现登录验证、路由守卫、动态路由加载。Vue Router 导航守卫、JWT、状态管理 (Pinia/Vuex)主题切换支持亮色/暗色主题或自定义主题。ElementPlus 自定义主题、CSS 变量数据表格与表单展示和操作数据的主要界面。el-table,el-form,el-pagination图标管理使用 SVG 图标提升灵活性和性能。封装SvgIcon组件使用h()渲染函数代码生成器根据模型自动生成 CRUD 代码提升开发效率。基于模板的代码生成示例一个简单的用户列表页面User.vue!-- src/views/system/User.vue -- template div el-card template #header div classcard-header span用户列表/span el-button typeprimary clickhandleAdd新增用户/el-button /div /template el-table :datatableData stylewidth: 100% el-table-column propdate label日期 width180 / el-table-column propname label姓名 width180 / el-table-column propaddress label地址 / el-table-column label操作 width180 template #defaultscope el-button sizesmall clickhandleEdit(scope.$index, scope.row) 编辑/el-button el-button sizesmall typedanger clickhandleDelete(scope.$index, scope.row) 删除/el-button /template /el-table-column /el-table el-pagination classpagination v-model:current-pagecurrentPage :page-size10 layouttotal, prev, pager, next, jumper :total100 current-changehandleCurrentChange / /el-card /div /template script setup import { ref } from vue const tableData ref([ { date: 2016-05-03, name: 张三, address: 北京市海淀区 }, // ... 更多数据 ]) const currentPage ref(1) const handleAdd () { console.log(新增用户) } const handleEdit (index, row) { console.log(编辑, index, row) } const handleDelete (index, row) { console.log(删除, index, row) } const handleCurrentChange (val) { console.log(当前页: ${val}) // 这里应发起请求获取对应页的数据 } /script style scoped .card-header { display: flex; justify-content: space-between; align-items: center; } .pagination { margin-top: 20px; justify-content: flex-end; } /style通过以上步骤你已经成功搭建了一个具备基础布局、动态路由菜单和基本功能模块的 Vue3 ElementPlus 后台管理系统框架。这个框架结构清晰、易于扩展可以作为大多数中后台项目的起点。后续可以根据具体业务需求在此基础上集成状态管理、API 封装、权限控制等更多高级功能 。参考来源Vue3.0商店后台管理系统项目实战-vue3搭配Element Plus框架使用Vue3实战二、搭建Vue3ElementPlus项目教程基于Vue3 Element Plus 的后台管理系统详细教程Vue3ElementPlus搭建后台管理系统模板Vue3教程开发一个 Vue 3 element-plus 的后台管理系统[vue3] 使用ElementPlus页面布局搭建架子