美文网首页
axiosDefaults

axiosDefaults

作者: 小柠有点萌 | 来源:发表于2020-08-12 10:00 被阅读0次

    axios.defaults.baseURL = 'http://127.0.0.1:8888';
    axios.defaults.withCredentials = true;
    axios.defaults.headers['Content-Type'] = 'application/x-www-form-urlencoded';
    axios.defaults.transformRequest = function (data) {
    if (!data) return data;
    let result = ``;
    for (let attr in data) {
    if (!data.hasOwnProperty(attr)) break;
    result += &${attr}=${data[attr]};
    }
    return result.substring(1);
    };
    axios.interceptors.response.use(function onFulfilled(response) {
    return response.data;
    }, function onRejected(reason) {
    return Promise.reject(reason);
    });

    相关文章

      网友评论

          本文标题:axiosDefaults

          本文链接:https://www.haomeiwen.com/subject/mcnwrktx.html