axios传递application/x-www-form-urlencoded格式的参数

转自:https://blog.csdn.net/lth002/article/details/140668236

export function $_login(data) {
  //加密登录
  return axios({
    method: "post",
    url: baseURL + "/admin/login/token",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded",
    },
    data,
    transformRequest: [
      function (data) {
        return transformData(data);
      },
    ],
  });
}
function transformData(data) {
  let ret = "";
  for (let it in data) {
    ret += encodeURIComponent(it) + "=" + encodeURIComponent(data[it]) + "&";
  }
  return ret;
}

posted @ 2024-08-23 20:26  长白山  阅读(318)  评论(0编辑  收藏  举报