Using proxytable to resolve cross-domain issues in Webpack+vue-cli+vue-resource

Source: Internet
Author: User

When the viewer reports such a mistake, it means that your request needs to cross the domain!

Here, I'm talking about using cross-domain issues in Webpack+vue-cli+vue-resource,

There is a configuration parameter called proxytable in the index.js file below the config file.

Proxytable: {      '/restful ': {        target: ' http://xxxxx/member/service/',        changeorigin:true,        pathrewrite:{//can not write            ' ^/restful ': '/restful '}}    ,

Changeorigin This parameter is set to True, it is possible to virtual a local proxy service to receive the request so that the cross-domain problem can be resolved target is the domain name of the interface you request

This can be written when the interface is called.

this. $http. Post (Commonurl + "/restful/member?op=getmember&access_token=111", {          op: ' GetMember ',        }). Then (response + =         }, response = {        });      },

related to API proxy Description, the use of this parameter.
Https://vuejs-templates.github.io/webpack/proxy.html

This parameter is mainly an address mapping table, you can set the complex URL simplification, for example, we want to request the address is API.XXXXXXXX.COM/LIST/1, can be set as follows:

Proxytable: {  '/list ': {    target: ' http://api.xxxxxxxx.com ',    pathrewrite: {//Can not write      ' ^/list ': '/ List '}}  }

So when we write the URL, only written /list/1 can represent api.xxxxxxxx.com/list/1.
so how to solve the cross-domain problem? In fact, in the above ' list ' parameter, there is a changeorigin parameter, receive a Boolean value, if set to True, then the local will be a virtual server to receive your request and send you the request, This will not have cross-domain issues, of course, this only applies to the development environment. The added code is as follows:

Proxytable: {  '/list ': {    target: ' http://api.xxxxxxxx.com ',    changeorigin:true,    pathrewrite: {      ' ^/list ': '/list '}}  

Using proxytable to resolve cross-domain issues in Webpack+vue-cli+vue-resource

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.