SpringBoot+Vue豆宝社区前后端分离项目手把手实战系列教程01---搭建前端工程

331 阅读2分钟

豆宝社区项目实战教程简介

本项目实战教程配有免费视频教程,配套代码完全开源。手把手从零开始搭建一个目前应用最广泛的Springboot+Vue前后端分离多用户社区项目。本项目难度适中,为便于大家学习,每一集视频教程对应在Github上的每一次提交。

项目首页截图

image

代码开源地址

前端 后端

视频教程地址

视频教程

前端技术栈

Vue Vuex Vue Router Axios Bulma Buefy Element Vditor DarkReader

后端技术栈

Spring Boot Mysql Mybatis MyBatis-Plus Spring Security JWT Lombok

搭建前端工程

1.创建vue工程

1.创建项目

npm i -g @vue/cli
vue create notepad_blog_frontend

2.选择

上下键移动,空格选择/取消

image-20210211143343349image-20210211143756452

大概意思就是说是否使用历史路由,这里为 n ,不使用

image-20210211144933627

将配置文件放到各自的文件里 还是 package.json(选择放到各自的文件里)

image-20210211145047228

**选择 n **

image-20210211145207792

进入到项目中 输入 npm run serve

image-20210211145544208

项目创建成功

.image-20210211145717119

2.添加框架/依赖

2.1下载

yarn add buefy   -- https://bulma.io/
yarn add element-ui
yarn add axios

buefy 的官网 bulma.io/

element-ui的官网 element.eleme.cn/#/zh-CN

在根目录下 package.json可以看到添加后的版本号image-20210211151115854

2.2引入

在/src/main.js中引入

// Buefy
import Buefy from 'buefy'
import 'buefy/dist/buefy.css'
// ElementUI
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';

Vue.use(Buefy)
Vue.use(ElementUI);

image-20210211152054727

3.实现通知效果

3.1修改 App.vue

将样式删除,将 class="container" 是Buefy中的一个类,页面会居中对齐,左右会有一定的间隔

<template>
  <!-- 是Buefy中的一个类,页面会居中对齐,左右会有一定的间隔 -->
  <div class="container">

    <router-view/>
  </div>
</template>

<style>

</style>

3.2修改router/index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: () => import('@/views/Home')
  }
]

const router = new VueRouter({
  routes
})

export default router

3.3删除页面

删除 /views/about页面

删除 components/HelloWorld.vue组件

3.4修改Home页面

<template>
  <div>
    <!-- 是Buefy中的一个类,页面以白色为背景 -->
    <div class="box">
      🔔  {{billboard}}
    </div>
  
  </div>
</template>

<script>


export default {
  name: 'Home',
  data() {
    return {
      billboard: '版本更新'
    }
  }
}
</script>

3.5启动项目查看效果

# 控制台输入启动命令
yarn serve

image-20210211154320612