vue2.0 using Axios to interact inside the pit

Source: Internet
Author: User

There are roughly three problems with Vue interacting with Axios:

1: Debugging cross-domain issues locally?

2:post request, the argument failed, causing the request to fail?

3:axios reference, referenced in the component used

Solution:

Question one: cross-domain?

Troubleshoot local debugging cross-domain issues?

Reverse proxy----This needs to be in the configuration file to change the configuration, there is a config below the index.js file

    

    

is not modified, as to the specific how to modify, you can Baidu, of course, if it is not the words on the debugging, first write the code well, NPM run build package to the background in his debugging

Issue two: The POST request, the argument is unsuccessful, causing the request to fail? (A GET request can be done directly according to the document)

Why?

Reason: Because the Axios POST request when the reference time and the traditional Ajax a little different, not the way from the submission, said the simple point in

If the interface you are requesting is this:http://localhost:8086/web/checkSkill/getSkillList? Key=123&currentpageno=1 , you'll have to deal with it.

How to deal with: Qs.stringify ();

        

          

Of course, you need to refer to the QS before use:

        

As for the need to first NPM install QS--save this with you, as if you can,

There is also a possible background to receive the parameter format is JSON object Format , what to do? See:

        

Just deal with that.

Question three: Axios reference

Is that you use the interaction in that component and you need to refer to it in this component first,

Is the import Axios from ' Axios ' I was in the overall (main.js) in the quote, and then began to use in other components, found not to work, only to quote,

Of course, before using axios do not forget, first install Axios NPM installed Axios--save Specific can read the document!!!!

    

Vue2.0 use Axios to interact inside the pit

Related Article

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.