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 腳手架初始化項目文件,具體步驟參考

vue.js 項目 環境搭建、運行、打包發佈(常規版)html

第二步:封裝頭部、側邊欄和公共容器組件

頭部:用戶信息等
側邊欄:用的elment-ui 的導航欄
公共容器:使用router-view 引入其餘子頁面,達到全部頁面公用頭部和側邊欄的效果vue

<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來區分路由地址webpack

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/...git

相關文章
相關標籤/搜索