Axios How to perform cross-domain and processing of return format callback function strings

Source: Internet
Author: User

Since vue2.0 began to not maintain the vue-resouce, instead of Axios, Axios official documents written in detail, attached to a link: http://www.jianshu.com/p/df464b26ae58

But I have a question after reading, cross-domain requests? Where (black question mark face), in the vue-resouce inside also has HTTP.JSONP carries on the JSONP cross domain, but Axios, after the inquiry, is needs to open the agent only then.

First, we need to make proxy settings in the index of Webpack config:

Add the following code:

'/api ' refers to, if we want to cross-domain, you can use/API instead of ' HTTP://R.PENGYOU.COM/FCG-BIN/CGI_GET_PORTRAIT.FCG ' this interface, the rest of the options what meaning to read the comments

So, how do we use it, look at the picture:

At this point we can now cross-domain request, if still can't cross-domain, that need to work with the background of small brother, let him in the background to open cross-domain, I previously wrote the background cross-domain method: http://www.cnblogs.com/mmykdbc/p/8024105.html

OK, look at the effect:

is a string, then we use the usual json.parse to convert is not feasible, because this is a callback function, then how do we convert it, on-line check a lot of methods, the original JS or JQ did not handle the callback function, so I can only in Str, I could intercept {} Inside the content ah, that in the conversion can be, say half of it, the code is as follows:

Perfect access to data:

Remember, you must restart the project after the configuration is complete, the configuration must be restarted after the project, the configuration must be restarted after the project; important thing to say three times!!!

Axios How to perform cross-domain and processing of return format callback function strings

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.