VUE-CLI and Axios implementations for cross domain access

Source: Internet
Author: User

Small make up I was just solved this problem, this time self-study also almost, small series will begin to do project, finally to solve the problem of routing and problems encountered.

My main solution is the routing problem, the recommended here is Axios, he can calculate a separate technology, node inside can use NG inside also can use, Vue inside more can use than Vue own Vue-rource, His best place, I think, of course, it's a good package. RESTful's requests are encapsulated and easy to use, and this time we will primarily cross domain issues.

The first thing I'm using is vue-cli is scaffolding, we need to configure his Cross-domain access request in Webpack inside the Config folder inside the index.js inside of the Dev Plus

Proxytable: {
      '/api ': {
        target: ' http://api.douban.com/v2 ',//Set the interface domain name and port number you call don't forget to add HTTP
        changeorigin:true ,
        pathrewrite: {
          ' ^/api ': '////
                Here is understood to replace the address in target with '/api ',
                /
                //////////////////// With ' Http://40.00.100.100:3002/user/add ', directly write '/api/user/add ' can}}
    ,
Don't forget to reboot your entire project, that is, NPM run Dev restarts the entire project.

You can see that it's been transferred.

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.