vue the post pass the request back to null value solution

Backstage pass on the values of those questions:
when to complete the registration function encountered some problems, for the following reasons:

 ```
 在向后台发送post请求的时候,后台不能接收到前端的传值(后台接收到的值全部为null)

Solution:
1. Set request header as header "Content-type": "file application / X-WWW-form-urlencoded"
2. Use qs conversion format
config.data = qs.stringify (config.data;
see, qs conversion out of the format similar to the address bar.

complete code:

import qs from "qs";

const axiosHttp = axios.create({
  baseURL: api.baseUrl
  // timeout: 3000,
  // headers: {
  //     'token':
  //     window.localStorage.csmpToken
  // }
});
//添加请求拦截器
axiosHttp.interceptors.request.use(
  config => {
    debugger;
    let access_token =
      "TGT-17-NT70Wd5zhqYkergIWdCuzcPLTjSFJEaxYniqfQYH302LcpGJFc-cas";
    if (config.method == "post") {
      config.headers = {
        token: access_token,
        "content-type": "application/x-www-form-urlencoded"
      };
      config.data = qs.stringify(config.data);
      console.log(config.data)
      
    }
    if (window.localStorage.dzsqToken)
      config.headers.token = window.localStorage.dzsqToken; //localstorage获取token
    config.headers.token = access_token;
    //在发送请求之前做某事
    return config;
  },
  error => {
    //请求错误时做些事
    return Promise.reject(error);
  }
);
Published 21 original articles · won praise 4 · Views 2733

Guess you like

Origin blog.csdn.net/smallico/article/details/102786313