Home > Web Front-end > JS Tutorial > body text

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

一个新手
Release: 2018-05-19 14:46:24
Original
4014 people have browsed it

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
Copy after login

Importing dependencies

import Qs from 'qs'
Copy after login

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);
    })
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template