日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > vue >内容正文

vue

spring boot + vue + element-ui全栈开发入门——前后端整合开发

發布時間:2025/6/16 vue 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 spring boot + vue + element-ui全栈开发入门——前后端整合开发 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、配置


?

思路是通過node的跨域配置來調用spring boot的rest api。

?

修改config\index.js文件,設置跨域配置proxyTable:

proxyTable: {'/api': {target: 'http://localhost:18080/',changeOrigin: true,pathRewrite: {'^/api': '/'}}}

  

完整的config\index.js代碼如下:

'use strict' // Template version: 1.3.1 // see http://vuejs-templates.github.io/webpack for documentation. const path = require('path')module.exports = {dev: {// PathsassetsSubDirectory: 'static',assetsPublicPath: '/',proxyTable: {'/api': {target: 'http://localhost:18080/',changeOrigin: true,pathRewrite: {'^/api': '/'}}},// Various Dev Server settingshost: 'localhost', // can be overwritten by process.env.HOSTport: 8080, // can be overwritten by process.env.PORT, if port is in use, a free one will be determinedautoOpenBrowser: true,errorOverlay: true,notifyOnErrors: true,poll: false, // https://webpack.js.org/configuration/dev-server/#devserver-watchoptions-/*** Source Maps*/// https://webpack.js.org/configuration/devtool/#developmentdevtool: 'cheap-module-eval-source-map',// If you have problems debugging vue-files in devtools,// set this to false - it *may* help// https://vue-loader.vuejs.org/en/options.html#cachebustingcacheBusting: true,cssSourceMap: true},build: {// Template for index.htmlindex: path.resolve(__dirname, '../dist/index.html'),// PathsassetsRoot: path.resolve(__dirname, '../dist'),assetsSubDirectory: 'static',assetsPublicPath: '/',/*** Source Maps*/productionSourceMap: true,// https://webpack.js.org/configuration/devtool/#productiondevtool: '#source-map',// Gzip off by default as many popular static hosts such as// Surge or Netlify already gzip all static assets for you.// Before setting to `true`, make sure to:// npm install --save-dev compression-webpack-pluginproductionGzip: false,productionGzipExtensions: ['js', 'css'],// Run the build command with an extra argument to// View the bundle analyzer report after build finishes:// `npm run build --report`// Set to `true` or `false` to always turn it on or off bundleAnalyzerReport: process.env.npm_config_report} } config\index.js

?

?

回到src\main.js文件中,注釋掉mock.js的配置

//開發模式開啟mock.js if (process.env.NODE_ENV === 'development') {// require('./mock') }

  

其他任何地方都不需要修改。

讓我們看看具體的效果:

?

?

觀察數據庫,發現已經保存到數據庫中了:

?

?二、總結


?

上述過程無疑體現了前后端分離開發的便利性。

?

?傳統方式是:作為前端開發者,必須等待后端程序員開發完畢之后才能做數據綁定,否則只能編寫假數據渲染到頁面上來模擬開發。等到后端開發完畢,又需要重新把頁面的假數據刪除,改用調用后端接口。這無疑增加了前端開發者的工作量。而且,當一方出現問題后,又需要協調工作才能把問題就解決。而這無疑也增加了溝通帶來的時間成本。

?

前后端分離方式是:前后端開發者一起定義好接口的規范,然后按照這個規范并行開發。前端開發者通過mock.js模擬并測試。后端開發者通過Unit Test來測試接口。當前后端都開發完畢后,只需要修改配置就可以了。避免了二次工作和重復性工作,而且也避免了需要等一方完成工作后自己再去工作的問題。

?

?

?

?

返回目錄

?

git代碼地址:https://github.com/carter659/spring-boot-vue-element.git

?

如果你覺得我的博客對你有幫助,可以給我點兒打賞,左側微信,右側支付寶。

有可能就是你的一點打賞會讓我的博客寫的更好:)

總結

以上是生活随笔為你收集整理的spring boot + vue + element-ui全栈开发入门——前后端整合开发的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。