基于Springboot+Vue的前后端分离的简单Demo案例(二)

前端搭建

Vue router 来动态构建左侧菜单

  • 导航1
    • 页面1
    • 页面2
  • 导航2
    • 页面3
    • 页面4
  • 导航3
    • 页面5
    • 页面6

在views目录下创建四个页面

PageOne.vue

<template>
  <h1>这是页面1</h1>
</template>
<script>
export default {
  name: "PageOne",
};
</script>
<style scoped></style>

配置路由:router/index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import Book from '../views/Book.vue'
import PageOne from '@/views/PageOne.vue'
import PageTwo from '@/views/PageTwo.vue'
import PageThree from '@/views/PageThree.vue'
import PageFour from '@/views/PageFour.vue'
import Nav from '@/views/Nav.vue'
import APP from '../App'
Vue.use(VueRouter)

const routes = [
  {
    path: "/nav1",
    name: "导航1",
    component: Nav,
    children: [
      {
        path: "/nav1/pageOne",
        name: "页面1",
        component: PageOne
      },
      {
        path: "/nav1/pageTwo",
        name: "页面2",
        component: PageTwo
      }
    ]
  },
  {
    path: "/nav2",
    name: "导航2",
    component: Nav,
    children: [
      {
        path: "/nav2/pageThree",
        name: "页面3",
        component: PageThree
      },
      {
        path: "/nav2/pageFour",
        name: "页面4",
        component: PageFour
      }
    ]
  }
]

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router
<template>
  <div id="app">
    <el-container style="height: 500px; border: 1px solid #eee">
      <el-aside width="200px" style="background-color: rgb(238, 241, 246)">
        <el-menu>
          <el-submenu index="1">
            <template slot="title"
              ><i class="el-icon-message"></i>导航一</template
            >
            <el-menu-item-group>
              <!-- <template slot="title">分组一</template> -->
              <el-menu-item index="1-1"
                ><router-link to="/nav1/pageOne"
                  >页面1</router-link
                ></el-menu-item
              >
              <el-menu-item index="1-2"
                ><router-link to="/nav1/pageTwo"
                  >页面2</router-link
                ></el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
        <el-menu>
          <el-submenu index="2">
            <template slot="title"><i class="el-icon-menu"></i>导航二</template>
            <el-menu-item-group>
              <!-- <template slot="title">分组一</template> -->
              <el-menu-item index="2-1"
                ><router-link to="/nav2/pageThree"
                  >页面3</router-link
                ></el-menu-item
              >
              <el-menu-item index="2-2"
                ><router-link to="/nav2/pageFour"
                  >页面4</router-link
                ></el-menu-item
              >
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
        <el-menu>
          <el-submenu index="3">
            <template slot="title"
              ><i class="el-icon-setting"></i>导航三</template
            >
            <el-menu-item-group>
              <!-- <template slot="title">分组一</template> -->
              <el-menu-item index="3-1">页面5</el-menu-item>
              <el-menu-item index="3-2">页面6</el-menu-item>
            </el-menu-item-group>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-container>
        <el-header style="text-align: right; font-size: 12px">
          <el-dropdown>
            <i class="el-icon-setting" style="margin-right: 15px"></i>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>查看</el-dropdown-item>
              <el-dropdown-item>新增</el-dropdown-item>
              <el-dropdown-item>删除</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <span>王小虎</span>
        </el-header>
        <!-- 内容 -->
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>
<style>
.el-header {
  background-color: #b3c0d1;
  color: #333;
  line-height: 60px;
}

.el-aside {
  color: #333;
}
</style>
<script>
export default {
  name: "App",
};
</script>

App.vue

<template>
  <div id="app">
    <router-view />
  </div>
</template>

<script>
export default {
  name: "App",
};
</script>

<style lang="scss"></style>

main.js

import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import axios from 'axios'
import VueRouter from 'vue-router'
//ElementUI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Vuex from 'vuex';
Vue.use(ElementUI);
Vue.use(VueRouter);
Vue.use(Vuex);

Vue.prototype.axios = axios;
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')

页面展示:

后端代码同上篇:基于Springboot+Vue的前后端分离的简单Demo案例(一)-CSDN博客

相关推荐
程序猿麦小七16 分钟前
基于springboot的景区网页设计与实现
java·spring boot·后端·旅游·景区
蓝田~24 分钟前
SpringBoot-自定义注解,拦截器
java·spring boot·后端
M_emory_25 分钟前
解决 git clone 出现:Failed to connect to 127.0.0.1 port 1080: Connection refused 错误
前端·vue.js·git
theLuckyLong25 分钟前
SpringBoot后端解决跨域问题
spring boot·后端·python
A陈雷25 分钟前
springboot整合elasticsearch,并使用docker desktop运行elasticsearch镜像容器遇到的问题。
spring boot·elasticsearch·docker
.生产的驴27 分钟前
SpringCloud Gateway网关路由配置 接口统一 登录验证 权限校验 路由属性
java·spring boot·后端·spring·spring cloud·gateway·rabbitmq
Ciito28 分钟前
vue项目使用eslint+prettier管理项目格式化
前端·javascript·vue.js
小扳30 分钟前
Docker 篇-Docker 详细安装、了解和使用 Docker 核心功能(数据卷、自定义镜像 Dockerfile、网络)
运维·spring boot·后端·mysql·spring cloud·docker·容器
v'sir40 分钟前
POI word转pdf乱码问题处理
java·spring boot·后端·pdf·word
李少兄44 分钟前
解决Spring Boot整合Redis时的连接问题
spring boot·redis·后端