In the use of VUE development process, it is unavoidable to go to the local data address request, and the original configuration in dev-server.js
, the new version vue-webpack-template
has been deleted dev-server.js
, instead webpack.dev.conf.js
, so configure local access in the webpack.dev.conf.js
configuration.
1 #webpack. Dev.conf.js2 //First3 //NODEJS Development Framework Express for simplified Operation4Const EXPRESS = require (' Express ')5 //create an instance of the node. JS Express Development Framework6Const APP =Express ()7 //the JSON address of the reference8 varAppData = require ('.. /data.json ')9 //JSON one keyTen varGoods =Appdata.result One A varApiroutes =Express. Router () -App.use ('/api ', apiroutes)
1. Get Request Configuration
const portfinder = require(‘portfinder‘)
After you add
1 #webpack. Dev.conf.js 2 // in the Devserver option, add the following : 3 before (APP) {4 app.get ('/api/someapi ', (req, res) + = {5 Res.json ({6 // Here is your JSON content 7 })8 })9 }
Note: After you modify the configuration file, you need to rerun the command npm run dev
.
2. Post request configuration.
If you want to configure a POST request, you need to configure the folder as follows:
1 #webpack. Dev.conf.js2Apiroutes.post ('/foods ',function(req, res) {//Note that this will be the post instead.3 Res.json ({4error:0,5 Data:foods6 });7 })8 //inside the component9 #...vueTen created () { One This. $http. Post (' Http://localhost:8080/api/foods '). Then (res) = { A Console.log (RES) - }) -}
From: http://blog.csdn.net/yiyinerjin/article/details/78667421
VUE-CLI load less than dev-server.js solution