Use Axios to send post requests in Vue

Source: Internet
Author: User

These days in the use of Vue Axios send GET request is very handy, but when sending a POST request is always in the successful callback function inside the return parameter does not exist, then wondered, after looking at the data, finally got the solution, here to do a summary:

First of all, we use the NPM install Axios will be installed by default QS, so we have to introduce QS into the Axios, and then need to instantiate a new Axios, and set his message header for ' Content-type ': ' Application /x-www-form-urlencoded '

1Let QS = require ('QS'); 2Let instance =Axios. Create ({3Headers: {'Content-type':'application/x-www-form-urlencoded' }4  });5Let data =qs.stringify ({6      "user_id": This. user_id,7      "Cate_name": This. Catename8    });9Instance.post ("./frontend/web/cate/create", data)Ten. Then (res = { One        if(Res.status = = $) { AAlert"Add success! ") -           This. Inittabledata (); -        } the      }) -.Catch(Err = { - Console.log (err); -});

This solves the problem of using Axios to send post requests in Vue.

Use Axios to send post requests in Vue

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.