Vue using Axios to request data across domains

Source: Internet
Author: User

Axios defaults to a method that does not have a JSONP cross-domain request. It is generally a popular practice to put the cross-domain in the background to resolve, that is, the background developers add cross-domain header information.

For example, in Java

Header,response.setheader ("Access-control-allow-origin", "www.allow-domain.com")

However, many times, the background for some reasons do not want to modify or have written JSONP interface needs to adapt to different platforms, at this point, the front-end can be introduced separately to solve the problem of dependency.

Introducing Dependencies

Install Jsonp

Import to Vue file

' Jsonp '

How to use it (refer to the documentation for JSONP on NPM)

Jsonp ("http://cross-domain.com",// replace URL     {        //JSONP callback function name        name: ' Success_jsonpcallback '    },    // Note the first argument is err, the second parameter is the data    function (err, data) {         console.log (data);    });

Vue using Axios to request data across domains

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.