The problem of using http-proxy-middleware post in vue-cli

data using http-proxy-middleware post in vue-cli is not passed to the server, and the server always returns empty data
in config/index.js

proxyTable: {
            "/api": {
                target: "http://192.168.1.86:9999/web",
                changeOrigin: true,
                pathRewrite: {
                    "^/api": ""
                }
        },

Global axios is configured

   import axios from "axios";
   Vue.prototype.$http = axios;  

request interface

let url = "api/"
this.$http({
            url: url,
            method: "post",
            data: {
                mobile: parseInt(this.phonenum),
                type: 1
            },
        }).then(res => {})
          .catch(err=>{})

after the request background succeeds, but the background does not receive data

Mar.03,2021
The format of the data transferred by

axios is quite different from the data format we usually transmit. I met this hole last time. The most commonly used data format for front-end browsers is Form Data, but the last time my project used axios, the data format was Request Payload, which makes the data format parsed by the back-end (PHP) different from the usual, but it is not the problem of the back-end, it is correct for our front-end to change the format to the commonly used Form Data format during transmission. You can take a look at this article Request Payload VS Form Data , and then check your console network to see if this is the problem. My solution is to use qs, or you can convert it directly to the correct format.


1. I understand that what you mean is that the backend received your request, but did not receive the data in your data. It may be because your data is not in the correct format, using

data: JSON.stringfy({
                mobile: parseInt(this.phonenum),
                type: 1
            })

try


is the status code of the console interface 200? See if response has any data?


initialize the configuration axios,create with a new service, setting header, and then convert the data to OK

import axios from 'axios';

import Qs from 'qs';
// axios
const service = axios.create({
    timeout: 5000, // 
    //postformdata
    headers: {
        "Content-Type": "application/x-www-form-urlencoded"
    },
    withCredentials: true, // cookie
    transformRequest: [function(data) {
        let newData = ''
        for (let k in data) {
            newData += encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) + '&'
        }
        return newData
    }],
    paramsSerializer: function(params) {
        return Qs.stringify(params);
    }
})

export default service
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1eadd77-2189.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1eadd77-2189.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?