Home  >  Article  >  Web Front-end  >  How to solve the problem that vue integrates axios and sends post request payload, causing the background to be unable to receive data.

How to solve the problem that vue integrates axios and sends post request payload, causing the background to be unable to receive data.

一个新手
一个新手Original
2018-05-19 14:46:244001browse

After integrating axios, vue will send post requests in payload mode by default. If you want to change to the normal method, you need to add headers and change the sent data json format to querystring.

Installing dependencies

cnpm install qs

Importing dependencies

import Qs from 'qs'

Use the following method where post is required, where postData is a json object

this.$http({
    url: '/api/act/yourApi.api',
    method: 'POST',
    headers: {        'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
    },
    data: Qs.stringify(postData)
})
    .then(res => {
        console.log(res);
    })
    .catch(err => {
        console.log(err);
    })

Like this, The data sent is sent in form-urlencodoed mode.

The above is the detailed content of How to solve the problem that vue integrates axios and sends post request payload, causing the background to be unable to receive data.. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn