Solve the problem that the vue processes parameters in the axios post request, vueaxios

Source: Internet
Author: User

Solve the problem that the vue processes parameters in the axios post request, vueaxios

Many of my friends will definitely use axios requests when using vue, including axios, which is already included in vux, which is easy to use and clearly described in this document, however, when we use post for submission, we find that sometimes the parameters are not sent to the server. I remember this situation also mentioned in the document, here, I will record the settings so that you can use them directly next time you need them. You do not need to read the Old Code.

The following is how to use vux. It is very simple to place the code in main. js. If you only use vue and directly install axios, the setting method is the same and will not be recorded.

Import qs from 'qs' import es6Promise from 'es6-promise 'import {AjaxPlugin} from 'vux 'vue. use (AjaxPlugin) AjaxPlugin. $ http. defaults. headers. post ['content-type'] = 'application/x-www-form-urlencoded' // POST parameter serialization (add request interceptor) AjaxPlugin. $ http. interceptors. request. use (config) => {// do something before sending the request if (config. method = 'post') {config. data = qs. stringify (config. data)} return config}, (error) =>{ return error })

Note:Placed before new Vue ({})

The above article solves the problem of using vue to process the axios post request for parameter passing. It is all the content that I have shared with you. I hope you can give us a reference and also hope you can provide more support for the customer's house.

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.