vue 搭建后台系统模块化开发详解
程序员文章站
2023-12-14 10:45:52
本文主要介绍了vue 搭建后台系统模块化开发,分享给大家,具体如下:
效果
目录结构
├── readme.md
├── build
│ ├── b...
本文主要介绍了vue 搭建后台系统模块化开发,分享给大家,具体如下:
效果
目录结构
├── readme.md ├── build │ ├── build.js │ ├── check-versions.js │ ├── logo.png │ ├── utils.js │ ├── vue-loader.conf.js │ ├── webpack.base.conf.js │ ├── webpack.dev.conf.js │ └── webpack.prod.conf.js ├── config │ ├── dev.env.js │ ├── index.js │ └── prod.env.js ├── index.html ├── package-lock.json ├── package.json ├── src │ ├── app.vue │ ├── assets │ │ └── logo.png │ ├── components │ │ ├── helloworld.vue │ │ ├── header.vue │ │ ├── home.vue │ │ └── leftbanner.vue │ ├── main.js │ ├── router │ │ └── index.js │ └── views │ ├── active.vue │ ├── listorder.vue │ ├── neworder.vue │ ├── system.vue │ └── user.vue └── static
实现方法:
第一步:使用vue-cli 脚手架初始化项目文件,具体步骤参考
第二步:封装头部、侧边栏和公共容器组件
头部:用户信息等
侧边栏:用的elment-ui 的导航栏
公共容器:使用router-view 引入其他子页面,达到所有页面公用头部和侧边栏的效果
<template> <div> <el-container> <el-header> <temheader></temheader> </el-header> <el-container> <el-aside> <temleftbanner></temleftbanner> </el-aside> <el-main > <transition name="move" mode="out-in"> <router-view class="main-container"></router-view> </transition> </el-main> </el-container> </el-container> </div> </template> <script> import temheader from './header.vue' import temleftbanner from './leftbanner.vue' export default { data () { return { } }, components: { // 组件 temheader, temleftbanner }, computed: { // 计算 }, methods: { // 方法事件 }, mounted () { // 加载完成 }, created () { // 创建 } } </script> <style lang='less'> .el-container{ height: 100vh; } .el-header, .el-footer { background-color: #b3c0d1; color: #333; text-align: center; line-height: 60px; } .el-aside { background-color: #d3dce6; color: #333; text-align: center; line-height: 200px; } .el-main { background-color: #e9eef3; color: #333; text-align: center; } .main-container{ max-width: 800px; margin: 0 auto; } body > .el-container { margin-bottom: 40px; } .el-container:nth-child(5) .el-aside, .el-container:nth-child(6) .el-aside { line-height: 260px; } .el-container:nth-child(7) .el-aside { line-height: 320px; } </style>
第三步:内容页面
│ └── views │ ├── active.vue │ ├── listorder.vue │ ├── neworder.vue │ ├── system.vue │ └── user.vue
第四步:路由
使用children来区分路由地址
import vue from 'vue' import router from 'vue-router' import home from '@/components/home' import listorder from '@/views/listorder' import neworder from '@/views/neworder' import active from '@/views/active' import system from '@/views/system' import user from '@/views/user' vue.use(router) export default new router({ routes: [ { path: '/', redirect: '/listorder' }, { path: '/', name: 'home', component: home, children: [ { path: '/listorder', name: 'listorder', component: listorder }, { path: '/neworder', name: 'neworder', component: neworder }, { path: '/active', name: 'active', component: active }, { path: '/system', name: 'system', component: system }, { path: '/user', name: 'user', component: user } ] }] })
项目地址:https://github.com/aimee1608/vuecommonmodule
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。