VUE-CLI load less than dev-server.js solution

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.