后台管理系统 vue+springboot 系列(2)

File.vue。文件管理

  • 使用了带选择的el-table,自定义el-table-column
  • 使用了el-分页
<template>
  <div>
    <div>
      <el-input style="width: 200px" placeholder="请输入名称" suffix-icon="el-icon-search" v-model="name"></el-input>
      <el-button  class="ml-5"  type="primary" @click="load">搜索</el-button>
      <el-button type="warning" @click="reset">重置</el-button>
    </div>

    <div style="margin-top: 10px">
      <el-upload
          style="display: inline-block"
          :action="'http://' + serverIp + ':9090/file/upload'"
          :on-success="handleFileUploadSuccess"
      >
        <el-button  type="primary">上传文件 <i class="el-icon-top"></i></el-button>
      </el-upload>
      <el-popconfirm
          class="ml-10"
          confirm-button-text='好的'
          cancel-button-text='不用了'
          icon="el-icon-info"
          icon-color="red"
          title="这是一段内容确定删除吗?"
          @confirm="delBatch"
      >
        <el-button slot="reference">批量删除 <i class="el-icon-remove-outline"></i></el-button>
      </el-popconfirm>
    </div>

    <el-table
        ref="multipleTable"
        :data="tableData"
        border stripe
        :header-cell-class-name="'headerBg'"
        tooltip-effect="dark"
        style="width: 100%; margin-top: 10px"
        @selection-change="handleSelectionChange">
      <el-table-column
          type="selection"
          width="55">
      </el-table-column>
      <el-table-column
          prop="id"
          label="ID"
          width="120">
      </el-table-column>
      <el-table-column prop="name" label="文件名称"></el-table-column>
      <el-table-column prop="type" label="文件类型"></el-table-column>
      <el-table-column prop="size" label="文件大小(kb)"></el-table-column>
      <el-table-column label="预览">
        <template slot-scope="scope">
          <el-button  type="primary"  @click="preview(scope.row.url)">预览</el-button>
        </template>
      </el-table-column>
      <el-table-column label="下载">
        <template slot-scope="scope">
          <el-button type="primary" @click="download(scope.row.url)">下载</el-button>
        </template>
      </el-table-column>
      <el-table-column label="启用">
        <template slot-scope="scope">
          <el-switch
              v-model="scope.row.enable"
              active-color="#13ce66"
              inactive-color="#ff4949"
              @change="changeEnable(scope.row)"
          >
          </el-switch>
        </template>
      </el-table-column>
      <el-table-column>
        <template slot-scope="scope">
          <el-popconfirm
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗?"
              @confirm="del(scope.row.id)"
          >
            <el-button type="danger" slot="reference">删除 <i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div class="block">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[2, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
export default {
  name: "File",
  data() {
    return {
      multipleSelection: [],
      tableData: [],
      serverIp: 'localhost',
      pageNum: 1,
      pageSize: 10,
      total: 0,
      name: '',
    }
  },
  created() {
    this.load()
  },
  methods: {
    del(id) {
      this.request.delete("/file/" + id).then(res => {
        if (res.code === '200') {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
    },
    download(url) {
      window.open(url)
    },
    preview(url) {
      window.open('https://file.keking.cn/onlinePreview?url=' + encodeURIComponent(window.btoa((url))))
    },
    changeEnable(row) {
      this.request.post("/file/update", row).then(res => {
        if (res.code === '200') {
          this.$message.success("操作成功")
        }
      })
    },
    handleSizeChange(pageSize) {
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },
    reset() {
      this.name = ""
      this.load()
    },
    load() {
      this.request.get("/file/page", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          name: this.name,
        }
      }).then(res => {

        this.tableData = res.data.records
        this.total = res.data.total

      })
    },
  }
}
</script>

<style scoped>

</style>

使用高德地图。
在public/index.html中添加
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=你申请的key"></script>
Map.vue

<template>
  <div>
    <div id="container" style="width: 100%; height: calc(100vh - 100px)"></div>

    <div id="info"></div>
  </div>
</template>

<script>
var content = [
  "<div style='font-size: 14px; color: red; width: 200px; height: 50px'>这是信息窗口</div>"
];


export default {
  name: "Map",
  data() {
    return {}
  },
  created() {

  },
  mounted() {
    // 创建地图实例
    var map = new AMap.Map("container", {
      zoom: 12,
      // center: [116.396901,39.919544],
      resizeEnable: true
    })

    var infoWindow = new AMap.InfoWindow({
      anchor: 'top-right',
      content: content.join("<br>")  //传入 dom 对象,或者 html 字符串
    });

    var clickHandler = function(e) {
      console.log('您在[ '+e.lnglat.getLng()+','+e.lnglat.getLat()+' ]的位置点击了地图!');

      infoWindow.open(map, [116.396901,39.919544]);
    };

    // 绑定事件
    // map.on('click', clickHandler);

    var marker = new AMap.Marker({
      position: new AMap.LngLat(116.396901,39.919544),   // 经纬度对象,也可以是经纬度构成的一维数组[116.39, 39.9]
      title: '北京故宫',
      icon: '//vdata.amap.com/icons/b18/1/2.png',
      // content: '<div style="font-size: 12px; width: 100px">这是我自定义的内容</div>'
    })
    marker.on('click', clickHandler);


    // 将创建的点标记添加到已有的地图实例:
    map.add(marker);


    // path 是驾车导航的起、途径和终点,最多支持16个途经点
    var path = []

    path.push([116.303843, 39.983412])
    path.push([116.321354, 39.896436])
    path.push([116.407012, 39.992093])

    map.plugin('AMap.DragRoute', function () {
      var route = new AMap.DragRoute(map, path, AMap.DrivingPolicy.LEAST_FEE)
      // 查询导航路径并开启拖拽导航
      route.search()
    })

    var polyLine = new AMap.Polyline({
      path: path,
      strokeWeight: 5,
      borderWeight: 5, // 线条宽度,默认为 1
      strokeStyle: "solid",
      strokeColor: '#DC143C', // 线条颜色
      lineJoin: 'round' // 折线拐点连接处样式
    })
    map.add(polyLine)



    //实例化城市查询类
    map.plugin('AMap.Geolocation', function() {
      var geolocation = new AMap.Geolocation({
        // 是否使用高精度定位,默认:true
        enableHighAccuracy: true,
        // 设置定位超时时间,默认:无穷大
        timeout: 10000,
        // 定位按钮的停靠位置的偏移量
        offset: [10, 20],
        //  定位成功后调整地图视野范围使定位位置及精度范围视野内可见,默认:false
        zoomToAccuracy: true,
        //  定位按钮的排放位置,  RB表示右下
        position: 'RB'
      })

      geolocation.getCurrentPosition(function(status,result){
        if(status=='complete'){
          onComplete(result)
        }else{
          onError(result)
        }
      });

      function onComplete (data) {
        // data是具体的定位信息
        console.log(data)
      }

      function onError (data) {
        // 定位出错
        console.error(data)
      }
    })

  },
  methods: {}
}
</script>

<style>

</style>

Article.vue。文章管理

  • 使用了带选择的el-table,
  • 使用了el-分页
  • 使用了el-dialog
  • 使用mavon-editor,md编辑器
<template>
  <div>
    <div style="margin: 10px 0">
      <el-input style="width: 200px" placeholder="请输入名称" suffix-icon="el-icon-search" v-model="name"></el-input>
      <el-button class="ml-5" type="primary" @click="load">搜索</el-button>
      <el-button type="warning" @click="reset">重置</el-button>
    </div>
    <div style="margin: 10px 0">
      <el-button type="primary" @click="handleAdd" v-if="user.role === 'ROLE_ADMIN'">新增 <i class="el-icon-circle-plus-outline"></i></el-button>
      <el-popconfirm
          class="ml-5"
          confirm-button-text='确定'
          cancel-button-text='我再想想'
          icon="el-icon-info"
          icon-color="red"
          title="您确定批量删除这些数据吗?"
          @confirm="delBatch"
      >
        <el-button type="danger" slot="reference">批量删除 <i class="el-icon-remove-outline"></i></el-button>
      </el-popconfirm>
    </div>

    <el-table :data="tableData" border stripe :header-cell-class-name="'headerBg'"
              @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55"></el-table-column>
      <el-table-column prop="id" label="ID" width="80"></el-table-column>
      <el-table-column prop="name" label="文章标题"></el-table-column>
      <el-table-column prop="content" label="文章内容">
        <template slot-scope="scope">
          <el-button @click="view(scope.row.content)" type="primary">查看内容</el-button>
        </template>
      </el-table-column>
      <el-table-column prop="user" label="发布人"></el-table-column>
      <el-table-column prop="time" label="发布时间"></el-table-column>
      <el-table-column label="操作" width="280" align="center">
        <template slot-scope="scope">
          <el-button type="success" @click="handleEdit(scope.row)" v-if="user.role === 'ROLE_ADMIN'">编辑 <i class="el-icon-edit"></i></el-button>
          <el-popconfirm
              class="ml-5"
              confirm-button-text='确定'
              cancel-button-text='我再想想'
              icon="el-icon-info"
              icon-color="red"
              title="您确定删除吗?"
              @confirm="del(scope.row.id)"
          >
            <el-button type="danger" slot="reference" v-if="user.role === 'ROLE_ADMIN'">删除 <i class="el-icon-remove-outline"></i></el-button>
          </el-popconfirm>
        </template>
      </el-table-column>
    </el-table>

    <div style="padding: 10px 0">
      <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[2, 5, 10, 20]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
      </el-pagination>
    </div>

    <el-dialog title="文章信息" :visible.sync="viewDialogVis" width="60%" >
      <el-card>
        <div>
          <mavon-editor
              class="md"
              :value="content"
              :subfield="false"
              :defaultOpen="'preview'"
              :toolbarsFlag="false"
              :editable="false"
              :scrollStyle="true"
              :ishljs="true"
          />
        </div>
      </el-card>
    </el-dialog>


    <el-dialog title="文章信息" :visible.sync="dialogFormVisible" width="60%" >
      <el-form label-width="80px" size="small">
        <el-form-item label="文章标题">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="文章内容">
          <mavon-editor ref="md" v-model="form.content" :ishljs="true" @imgAdd="imgAdd"/>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="save">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
export default {
  name: "Article",
  data() {
    return {
      form: {},
      content: '',
      tableData: [],
      name: '',
      multipleSelection: [],
      pageNum: 1,
      pageSize: 10,
      total: 0,
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      dialogFormVisible: false,
      viewDialogVis: false
    }
  },
  created() {
    this.load()
  },
  methods: {
    view(content) {
      this.content = content
      this.viewDialogVis = true
    },
    load() {
      this.request.get("/article/page", {
        params: {
          pageNum: this.pageNum,
          pageSize: this.pageSize,
          name: this.name,
        }
      }).then(res => {

        this.tableData = res.data.records
        this.total = res.data.total

      })
    },
    handleAdd() {
      this.dialogFormVisible = true
      this.form = {}
    },
    handleEdit(row) {
      this.form = JSON.parse(JSON.stringify(row))
      this.dialogFormVisible = true
    },
    // 绑定@imgAdd event
    imgAdd(pos, $file) {
      let $vm = this.$refs.md
      // 第一步.将图片上传到服务器.
      const formData = new FormData();
      formData.append('file', $file);
      axios({
        url: 'http://localhost:9090/file/upload',
        method: 'post',
        data: formData,
        headers: {'Content-Type': 'multipart/form-data'},
      }).then((res) => {
        // 第二步.将返回的url替换到文本原位置![...](./0) -> ![...](url)
        $vm.$img2Url(pos, res.data);
      })
    },
    del(id) {
      this.request.delete("/article/" + id).then(res => {
        if (res.code === '200') {
          this.$message.success("删除成功")
          this.load()
        } else {
          this.$message.error("删除失败")
        }
      })
    },
    handleSelectionChange(val) {
      console.log(val)
      this.multipleSelection = val
    },
    delBatch() {
      let ids = this.multipleSelection.map(v => v.id)  // [{}, {}, {}] => [1,2,3]
      this.request.post("/article/del/batch", ids).then(res => {
        if (res.code === '200') {
          this.$message.success("批量删除成功")
          this.load()
        } else {
          this.$message.error("批量删除失败")
        }
      })
    },
    save() {
      this.request.post("/article", this.form).then(res => {
        if (res.code === '200') {
          this.$message.success("保存成功")
          this.dialogFormVisible = false
          this.load()
        } else {
          this.$message.error("保存失败")
        }
      })
    },
    reset() {
      this.name = ""
      this.load()
    },
    handleSizeChange(pageSize) {
      console.log(pageSize)
      this.pageSize = pageSize
      this.load()
    },
    handleCurrentChange(pageNum) {
      console.log(pageNum)
      this.pageNum = pageNum
      this.load()
    },
    download(url) {
      window.open(url)
    },
  }
}
</script>

<style scoped>

</style>

router/index.js

  • 定义routes
  • 创建VueRouter实例
  • 提供重置router,用于用户下线
  • 设置routes的方法,用于动态路由
  • 一个全局前置导航守卫,拦截未定义路径,未登录跳转到login
import Vue from 'vue'
import VueRouter from 'vue-router'
import store from "@/store";

Vue.use(VueRouter)

const routes = [
    {
        path: '/login',
        name: 'Login',
        component: () => import('../views/login/Login.vue')
    },
    {
        path: '/register',
        name: 'Register',
        component: () => import('../views/Register.vue')
    },
    {
        path: '/404',
        name: '404',
        component: () => import('../views/404.vue')
    },
    {
        path: '/front',
        name: 'Front',
        component: () => import('../views/front/Front'),
        children: [
            {
                path: 'home',
                name: 'FrontHome',
                component: () => import('../views/front/Home.vue')
            },
            {
                path: 'item1',
                name: 'Item1',
                component: () => import('../views/front/Item1.vue')
            },
            {
                path: 'person',
                name: 'FrontPerson',
                component: () => import('../views/front/Person')
            },
            {
                path: 'password',
                name: 'FrontPassword',
                component: () => import('../views/front/Password')
            },
            {
                path: 'video',
                name: 'Video',
                component: () => import('../views/front/Video')
            },
            {
                path: 'videoDetail',
                name: 'VideoDetail',
                component: () => import('../views/front/VideoDetail')
            },
            {
                path: 'article',
                name: 'FrontArticle',
                component: () => import('../views/front/Article')
            },
            {
                path: 'articleDetail',
                name: 'ArticleDetail',
                component: () => import('../views/front/ArticleDetail')
            },
        ]
    },
]


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

// 提供一个重置路由的方法
export const resetRouter = () => {
    router.matcher = new VueRouter({
        mode: 'history',
        base: process.env.BASE_URL,
        routes
    })
}


// 注意:刷新页面会导致页面路由重置
export const setRoutes = () => {
    const storeMenus = localStorage.getItem("menus");
    if (storeMenus) {

        // 获取当前的路由对象名称数组
        const currentRouteNames = router.getRoutes().map(v => v.name)
        if (!currentRouteNames.includes('Manage')) {
            // 拼装动态路由
            const manageRoute = { path: '/', name: 'Manage', component: () => import('../views/Manage.vue'), redirect: "/home", children: [
                    { path: 'person', name: '个人信息', component: () => import('../views/Person.vue')},
                    { path: 'password', name: '修改密码', component: () => import('../views/Password.vue')}
                ] }
            const menus = JSON.parse(storeMenus)
            console.log(menus);
            menus.forEach(item => {
                if (item.path) {  // 当且仅当path不为空的时候才去设置路由
                    let itemMenu = { path: item.path.replace("/", ""), name: item.name, component: () => import('../views/' + item.pagePath + '.vue')}
                    manageRoute.children.push(itemMenu)
                } else if(item.children.length) {
                    item.children.forEach(item => {
                        if (item.path) {
                            let itemMenu = { path: item.path.replace("/", ""), name: item.name, component: () => import('../views/' + item.pagePath + '.vue')}
                            manageRoute.children.push(itemMenu)
                        }
                    })
                }
            })
            console.log(manageRoute);
            // 动态添加到现在的路由对象中去
            router.addRoute(manageRoute)
        }

    }
}

setRoutes();


router.beforeEach((to, from, next) => {
    localStorage.setItem("currentPathName", to.name)  // 设置当前的路由名称
    store.commit("setPath")

    // 未找到路由的情况
    if (!to.matched.length) {
        const storeMenus = localStorage.getItem("menus")
        if (storeMenus) {
            next("/404")
        } else {
            // 跳回登录页面
            next("/login")
        }
    }
    // 其他的情况都放行
    next()
})

export default router;

Person.vue .个人信息

  • 使用了el-upload,使用了text-align在让子元素居中
  • 使用了el-from
<template>
  <div>
    <el-card style="width: 500px;" >
      <el-upload
          class="avatar-uploader"
          :action="'http://' + serverIp +':9090/file/upload'"
          :show-file-list="false"
          :on-success="handleAvatarSuccess"
      >
        <img v-if="form.avatarUrl" :src="form.avatarUrl" class="avatar">
        <i v-else class="el-icon-plus avatar-uploader-icon"></i>
      </el-upload>

      <el-form label-width="80px"  size="small" :model="form">

        <el-form-item label="用户名">
          <el-input v-model="form.username" disabled autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="昵称">
          <el-input v-model="form.nickname" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="邮箱">
          <el-input v-model="form.email" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="电话">
          <el-input v-model="form.phone" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="地址">
          <el-input type="textarea"  v-model="form.address" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="save">确 定</el-button>
        </el-form-item>
      </el-form>
    </el-card>


  </div>
</template>

<script>
export default {
  name: "Person",
  data() {
    return {
      form: {},
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      serverIp: 'localhost',
    }
  },
  created() {
    this.getUser().then(res => {
      console.log(res)
      this.form = res
    })
  },
  methods: {
    save() {
      this.request.post("/user", this.form).then(res => {
        if (res.code === '200') {
          this.$message.success("保存成功")

          // 触发父级更新User的方法
          this.$emit("refreshUser")

          // 更新浏览器存储的用户信息
          this.getUser().then(res => {
            res.token = JSON.parse(localStorage.getItem("user")).token
            localStorage.setItem("user", JSON.stringify(res))
          })

        } else {
          this.$message.error("保存失败")
        }
      })
    },
    handleAvatarSuccess(res) {
      this.form.avatarUrl = res
    },
    async getUser() {
      return (await this.request.get("/user/username/" + this.user.username)).data
    },
  }
}
</script>

<style scoped>
.avatar-uploader {
  text-align: center;
  padding: 10px;
}
.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
}
.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 138px;
  height: 138px;
  line-height: 138px;
  text-align: center;
}
.avatar {
  width: 138px;
  height: 138px;
  display: block;
}
</style>

font/Front.vue 。学生页面总体。

  • 使用了flex,对于文字使用了line-height来使文字居中对齐,使用了align-items来居中对齐图片文字
  • 使用了el-menu、使用了el-dropdown-menu下拉菜单
<template>
  <div>
    <div style="display: flex; height: 60px; line-height: 60px;">
      <div style="display: flex; align-items: center;width: 300px;">
        <img src="../../assets/logo1.png" alt=""
             style="width: 3em; height: 3em; margin-left: 20px;"
        >
        <span style="margin-left: 10px;">欢迎来到xx系统</span>
      </div>
      <div style="flex: 1">
        <el-menu :default-active="'1'" class="el-menu-demo" mode="horizontal" router>
          <el-menu-item index="/front/home">首页</el-menu-item>
          <el-menu-item index="/front/video">视频播放</el-menu-item>
          <el-menu-item index="/front/article">文章列表</el-menu-item>
          <el-submenu index="2">
            <template slot="title">我的工作台</template>
            <el-menu-item index="/front/item1">选项1</el-menu-item>
            <el-menu-item index="2-2">选项2</el-menu-item>
            <el-menu-item index="2-3">选项3</el-menu-item>
            <el-submenu index="2-4">
              <template slot="title">选项4</template>
              <el-menu-item index="2-4-1">选项1</el-menu-item>
              <el-menu-item index="2-4-2">选项2</el-menu-item>
              <el-menu-item index="2-4-3">选项3</el-menu-item>
            </el-submenu>
          </el-submenu>
          <el-menu-item index="3" disabled>消息中心</el-menu-item>
          <el-menu-item index="4"><a href="https://www.ele.me" target="_blank">订单管理</a></el-menu-item>
        </el-menu>
      </div>
      <div style="width: 200px">
        <div v-if="!user.username">
          <el-button @click="$router.push('/login')">登录</el-button>
          <el-button @click="$router.push('/register')">注册</el-button>
        </div>
        <div v-else>
          <el-dropdown>
            <div>
              <img :src="user.avatarUrl">
              <span>{{ user.nickname }}</span><i class="el-icon-arrow-down"></i>
            </div>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item>
                <router-link to="/front/password">修改密码</router-link>
              </el-dropdown-item>
              <el-dropdown-item>
                <span @click="$router.replace('/front/person')">个人信息</span>
              </el-dropdown-item>
              <el-dropdown-item>
                <span @click="logout">退出</span>
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </div>
      </div>
    </div>
    <div style="width: 1000px; margin: 0 auto">
      <router-view />
    </div>
  </div>
</template>

<script>
export default {
  name: "Front",
  data() {
    return {
      user: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {}
    }
  },
  created() {

  },
  methods: {
    logout() {
      this.$store.commit("logout")
      this.$message.success("退出成功")
    }
  }
}
</script>

<style>

</style>

front/Home.vue。首页

  • 使用了走马灯,el-carousel
<template>
  <div>
    <el-carousel height="450px">
      <el-carousel-item v-for="item in imgs" :key="item">
        <img :src="item" alt="" >
      </el-carousel-item>
    </el-carousel>
  </div>
</template>

<script>
export default {
  name: "FrontHome",
  data() {
    return {
      imgs: [
        'https://img30.360buyimg.com/babel/s1580x830_jfs/t1/109361/24/22897/74054/621ede58E099d37e3/f12730c81df6046a.jpg!cc_1580x830.webp',
        'https://img13.360buyimg.com/babel/s1580x830_jfs/t1/96398/30/23715/70228/6221e9d0Ec1b9fe65/f66e2ad76314d6cd.jpg!cc_1580x830.webp'
      ],
      files: []
    }
  },

  methods: {

  }
}
</script>

<style>

</style>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: Vue 3 和 Spring Boot 是一对强大的技术组合,可用于搭建现代化的后台管理系统。下面是一个基本的指南,介绍如何从零开始搭建一个 Vue 3 + Spring Boot 后台管理系统。 首先,我们需要准备开发环境。在电脑上安装好 Node.js 和 Java JDK,并配置好环境变量。然后,安装 Vue CLI 和 Spring Boot CLI,这些工具将帮助我们创建和管理项目。 第二步是创建一个新的 Spring Boot 项目。使用 Spring Boot CLI,我们可以快速创建一个空的 Spring Boot 项目,并进行基本的配置。可以使用命令行,输入如下命令来创建项目: ``` $ spring init --name=my-project --groupId=com.example --artifactId=my-project --dependencies=web my-project ``` 这将创建一个名为 my-project 的 Spring Boot 项目。 接下来,我们可以创建一个 Vue 3 项目。使用 Vue CLI,我们可以选择一个预定义的模板,例如 Vue Router 和 Vuex,以及一些常用的插件。可以使用命令行,输入如下命令来创建项目: ``` $ vue create my-project ``` 这将创建一个名为 my-project 的 Vue 3 项目。 现在,我们已经有了一个空的 Spring Boot 项目和一个空的 Vue 3 项目。接下来,我们需要将这两者连接起来。 在 Vue 3 项目中,可以使用 axios 或者 fetch 来发送请求到后端。在 Spring Boot 项目中,可以使用 Spring Data JPA 来管理数据库,Spring Boot Security 来进行身份验证和授权。 我们可以编写 RESTful API 接口,用于在前端和后端之间传输数据。同时,也需要编写前端组件和页面,以及后端的 Controller 和 Service 层代码,来实现各种功能。 最后,我们可以使用打包和部署工具,将项目打包为可部署的文件,并将其部署到服务器上。例如,可以使用 Maven 将 Spring Boot 项目打包为 Java 可执行文件(JAR 文件),并使用 Nginx 或 Apache 将 Vue 3 项目部署为静态文件。 总之,使用 Vue 3 和 Spring Boot 可以快速搭建一个功能丰富的后台管理系统。只需按照上述步骤创建项目、编写代码、连接前后端,最后打包部署即可。当然,在实际开发过程中还需要考虑安全性、性能优化和代码质量等方面的问题,这些都需要进一步的学习和实践。 ### 回答2: Vue3是一个流行的JavaScript框架,用于构建用户界面。Spring Boot是一个基于Java的框架,用于构建快速且易于配置的应用程序。下面是在Vue3和Spring Boot中从零搭建后台管理系统的步骤: 1. 搭建Spring Boot后端: - 在IDE中创建一个新的Spring Boot项目。 - 添加所需的依赖项,如Spring Security、Spring Data JPA和MySQL数据库驱动程序。 - 创建实体类和存储库接口,用于管理系统数据的持久化。 - 创建控制器类,用于处理来自前端的请求,并调用适当的服务方法。 - 配置数据库连接和安全性设置。 - 运行应用程序,确保后端正常工作。 2. 搭建Vue3前端: - 在命令行中使用Vue CLI创建一个新的Vue3项目。 - 在Vue3项目中安装所需的依赖项,如Vue Router和Axios。 - 创建路由配置文件,定义前端路由和对应的组件。 - 创建后台API服务文件,使用Axios发送HTTP请求到后端。 - 创建所需的组件,如登录、注册、用户管理和权限管理。 - 配置应用程序的主要入口点,并将路由和组件添加到Vue实例中。 - 运行应用程序,确保前端正常工作。 3. 连接前端和后端: - 在Vue3中使用Axios调用后端API。 - 在Spring Boot中创建适当的控制器和服务方法,以接收和处理来自前端的请求。 - 在Vue3中处理返回的数据,并根据需要进行展示和处理。 4. 完善功能和界面设计: - 根据系统需求和设计规范,完善后台管理系统的功能和界面。 - 添加用户认证和授权功能,确保只有授权用户才能访问特定页面和功能。 - 使用Vue3的组件化和响应式特性,实现良好的用户体验。 - 进行测试和调试,确保系统稳定性和安全性。 以上是使用Vue3和Spring Boot搭建后台管理系统的一般步骤,具体的实施过程可能因项目需求和个人偏好而有所不同。在开始搭建项目之前,建议先了解Vue3和Spring Boot的基本知识,并参考官方文档和教程,以帮助顺利完成项目。 ### 回答3: 搭建一个基于Vue3和Spring Boot的后台管理系统,需要经过以下步骤: 1. 确保你已经安装了Node.js和Java开发环境。可以从官网上下载并按照指引进行安装。 2. 创建Vue3项目。使用命令行工具或者Vue CLI来创建一个新的Vue3项目。运行命令`vue create project-name`,然后根据指引选择需要的配置项,比如包管理工具、路由、状态管理等。等待项目创建完成。 3. 构建前端界面。在Vue3项目中,根据需求使用Vue组件来搭建前端界面。可以使用Vue3提供的Composition API来编写组件逻辑,通过Vue Router来管理路由,使用Vuex来管理状态。 4. 编写API接口。使用Spring Boot来构建后端服务。创建一个Spring Boot项目,添加所需的依赖,如Spring Web、Spring Data JPA等。编写API接口的Controller类,定义各个接口的URL映射和请求处理方法。 5. 连接数据库。使用Spring Data JPA或其他适当的技术在后台系统中连接数据库。配置数据库连接信息,创建实体类和仓库接口,实现对数据库的增删改查操作。 6. 实现前后端交互。在Vue3项目中,使用axios或其他合适的HTTP库发送HTTP请求到后端接口,获取数据并进行展示。前端页面通过调用API接口来实现数据的增删改查操作。 7. 运行和部署。在开发过程中可以使用命令行运行Vue3前端项目和Spring Boot后端项目,通过不同的端口来访问前后端。在开发完成后,可以使用打包工具如Webpack将前端项目打包成静态文件,然后将打包结果部署到服务器,运行Spring Boot项目。 通过以上步骤,你就可以搭建一个基于Vue3和Spring Boot的后台管理系统。这个系统可以实现前后端分离,通过API接口进行数据交互,具备良好的可扩展性和可维护性。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值