【无标题】

springboot+vue小白升级之路01-使用vue快速搭建一个管理系统页面框架和数据渲染

applicatin.properties简单配置一下

server.port=8089
 
 

项目内建vue模块,

pom.xml


 
 
  1. <dependencies >
  2. <dependency >
  3. <groupId >org.springframework.boot < /groupId >
  4. <artifactId >spring-boot-starter-web < /artifactId >
  5. < /dependency >
  6. <dependency >
  7. <groupId >org.springframework.boot < /groupId >
  8. <artifactId >spring-boot-configuration-processor < /artifactId >
  9. < optional > true < / optional >
  10. < /dependency >
  11. <dependency >
  12. <groupId >org.projectlombok < /groupId >
  13. <artifactId >lombok < /artifactId >
  14. < optional > true < / optional >
  15. < /dependency >
  16. <dependency >
  17. <groupId >org.springframework.boot < /groupId >
  18. <artifactId >spring-boot-starter-test < /artifactId >
  19. <scope > test < /scope >
  20. < /dependency >
  21. < /dependencies >

下面我们开始springboot+ vue前后端分离项目的小白学习之路。

在assets文件夹中,新建一个css文件,重置样式

global.css


 
 
  1. html, body{
  2. margin: 0;
  3. padding: 0;
  4. }
  5. * {
  6. box-sizing: border-box;
  7. }

main.js


 
 
  1. import Vue from 'vue'
  2. import App from './App.vue'
  3. import store from '@/store'
  4. import router from "@/router";
  5. import ElementUI from 'element-ui';
  6. import 'element-ui/lib/theme-chalk/index.css';
  7. import axios from "axios";
  8. import * as echarts from 'echarts'
  9. import '@/assets/global.css'
  10. Vue. prototype. $echarts = echarts;
  11. axios. defaults. baseURL= 'http://localhost:8089';
  12. Vue. prototype. $http = axios;
  13. Vue. use( ElementUI,{ size: 'small'});
  14. Vue. config. productionTip = false;
  15. new Vue({
  16. render: h => h( App),
  17. store,
  18. router
  19. }).$mount( '#app');

app.vue


 
 
  1. <template >
  2. <div id = "app" >
  3. <el-container class = "container" >
  4. <el-header class = "header-area" >
  5. <img src = "./assets/logo.png" alt = "logo" class = "logo" >
  6. <span class = "title" >手牵手带小白做毕设 < /span >
  7. < /el-header >
  8. <el-container class = "middle-area" >
  9. <el-aside class = "left-aside" >
  10. <el-menu
  11. :default-active = "$route.path"
  12. class = "el-menu-vertical-demo"
  13. background-color = "#545c64"
  14. text-color = "#fff"
  15. active-text-color = "#ffd04b"
  16. router >
  17. <el-menu-item index = "/home" >
  18. <i class = "el-icon-menu" > < /i >
  19. <span slot = "title" >系统首页 < /span >
  20. < /el-menu-item >
  21. <el-submenu >
  22. <template slot = "title" >
  23. <i class = "el-icon-location" > < /i >
  24. <span >用户管理 < /span >
  25. < /template >
  26. <el-menu-item-group >
  27. <el-menu-item index = "/admin" >管理员信息 < /el-menu-item >
  28. <el-menu-item index = "/user" >用户信息 < /el-menu-item >
  29. < /el-menu-item-group >
  30. < /el-submenu >
  31. <el-submenu index = "3" >
  32. <template slot = "title" >
  33. <i class = "el-icon-location" > < /i >
  34. <span >信息管理 < /span >
  35. < /template >
  36. <el-menu-item-group >
  37. <el-menu-item index = "3-1" >xxx信息 < /el-menu-item >
  38. <el-menu-item index = "3-2" >yyy信息 < /el-menu-item >
  39. < /el-menu-item-group >
  40. < /el-submenu >
  41. < /el-menu >
  42. < /el-aside >
  43. <el-main >
  44. <router-view / >
  45. < /el-main >
  46. < /el-container >
  47. < /el-container >
  48. < /div >
  49. < /template >
  50. <style lang = "scss" >
  51. .container{
  52. height: 100vh;
  53. .header-area{
  54. background-color: # 4c 535a;
  55. .logo {
  56. width: 40px;
  57. position: relative;
  58. top: 10px;
  59. }
  60. .title{
  61. font-size: 20px;
  62. margin-left: 15px;
  63. color: white;
  64. }
  65. }
  66. .middle-area{
  67. .left-aside{
  68. overflow: hidden;
  69. height: 100%;
  70. / *background-color: # 545c 64; * /
  71. width: 230px !important;
  72. .el-menu-vertical-demo{
  73. height: 100%;
  74. }
  75. }
  76. }
  77. }
  78. < /style >

home.vue


 
 
  1. <template >
  2. <div >
  3. <div style = "font-size: 18px;margin: 15px 0;" >手牵手教小白做毕设 < /div >
  4. <div style = "font-size: 18px;margin: 15px 0;" >大家给个一键三连 < /div >
  5. <div style = "font-size: 18px;margin: 15px 0;" >感谢大家 < /div >
  6. < /div >
  7. < /template >
  8. <script >
  9. export default {
  10. name: "HomeView"
  11. }
  12. < /script >
  13. <style scoped >
  14. < /style >

views文件夹下,新建User文件夹,内建两个vue文件

adminView.vue


 
 
  1. <template >
  2. <div >
  3. <!-- 搜索区域 -- >
  4. <div style = "margin-bottom:15px;" >
  5. <el-input v-model = "input" style = "width:200px;" placeholder = "请输入内容" > < /el-input >
  6. <el-button type = "warning" style = "margin-left: 10px;" icon = "el-icon-search" >查询 < /el-button >
  7. <el-button type = "primary" style = "margin-left: 10px;" icon = "el-icon-plus" >新增 < /el-button >
  8. < /div >
  9. <el-table
  10. : data = "tableData"
  11. style = "width: 100%" >
  12. <el-table-column
  13. prop = "date"
  14. label = "日期" >
  15. < /el-table-column >
  16. <el-table-column
  17. prop = "name"
  18. label = "姓名" >
  19. < /el-table-column >
  20. <el-table-column
  21. prop = "address"
  22. label = "地址" >
  23. < /el-table-column >
  24. <el-table-column label = "操作" >
  25. <template slot-scope = "scope" >
  26. <el-button type = "primary" icon = "el-icon-edit" >编辑 < /el-button >
  27. <el-button type = "danger" icon = "el-icon-delete" >删除 < /el-button >
  28. < /template >
  29. < /el-table-column >
  30. < /el-table >
  31. <div style = "margin-top:15px;" >
  32. <el-pagination
  33. @size-change = "handleSizeChange"
  34. @current-change = "handleCurrentChange"
  35. :current-page = "currentPage"
  36. :page-sizes = "[10, 20, 30, 40]"
  37. :page-size = "100"
  38. layout = "total, sizes, prev, pager, next, jumper"
  39. :total = "400" >
  40. < /el-pagination >
  41. < /div >
  42. < /div >
  43. < /template >
  44. <script >
  45. export default {
  46. name: "AdminView",
  47. dat a() {
  48. return {
  49. tableData: [{
  50. date: '2016-05-02',
  51. name: '王小虎',
  52. address: '上海市普陀区金沙江路 1518 弄'
  53. }, {
  54. date: '2016-05-04',
  55. name: '王小虎',
  56. address: '上海市普陀区金沙江路 1517 弄'
  57. }, {
  58. date: '2016-05-01',
  59. name: '王小虎',
  60. address: '上海市普陀区金沙江路 1519 弄'
  61. }, {
  62. date: '2016-05-03',
  63. name: '王小虎',
  64. address: '上海市普陀区金沙江路 1516 弄'
  65. }],
  66. currentPage: 1,
  67. }
  68. },
  69. methods: {
  70. handleSizeChange(val) {
  71. console.log(`每页 ${val} 条`);
  72. },
  73. handleCurrentChange(val) {
  74. console.log(`当前页: ${val}`);
  75. }
  76. }
  77. }
  78. < /script >
  79. <style scoped >
  80. < /style >

userView.vue


 
 
  1. <template >
  2. <div >UserView < /div >
  3. < /template >
  4. <script >
  5. export default {
  6. name: "UserView"
  7. }
  8. < /script >
  9. <style scoped >
  10. < /style >

在src文件下,新建router文件夹,新建index.js文件


 
 
  1. import Vue from 'vue'
  2. import VueRouter from 'vue-router'
  3. Vue.use(VueRouter)
  4. const routes = [
  5. {
  6. path: '/',
  7. redirect: '/home',
  8. },
  9. {
  10. path: '/home',
  11. name: 'HomeView',
  12. component: ()=> import( '@/views/HomeView.vue'),
  13. },
  14. {
  15. path: '/admin',
  16. name: 'AdminView',
  17. component: ()=> import( '@/views/User/AdminView.vue'),
  18. },
  19. {
  20. path: '/user',
  21. name: 'UserView',
  22. component: ()=> import( '@/views/User/UserView.vue'),
  23. },
  24. ]
  25. const router = new VueRouter({
  26. routes
  27. })
  28. export default router

在src文件夹下,新建store文件夹,内建index.js


 
 
  1. import Vue from 'vue'
  2. import Vuex from 'vuex'
  3. Vue. use(Vuex)
  4. export default new Vuex. Store({
  5. state: {
  6. },
  7. getters: {
  8. },
  9. mutations: {
  10. },
  11. actions: {
  12. },
  13. modules: {
  14. }
  15. })

好,至此,一个拥有后台和前端的项目搭建完成。后期我们学习的代码内容,我会在这个项目中陆续添加进去。

测试,运行

文章知识点与官方知识档案匹配,可进一步学习相关知识
Java技能树首页概览 140504 人正在系统学习中
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值