When you use axios to call the background interface, baseurl itself becomes localhost,. How to change it?

my axios function:
import axios from "axios"
import Qs from" qs"
export default {

post: function (url, data) {
    axios.defaults.headers.post["Content-Type"] = "application/x-www-form-urlencoded";
    let config = {
        //axios.get(url,config);urlconfigurl
        url: url,

        // 
        method: "post", // default
        // url
        baseURL: "https://39.104.91.74:8080/",

        transformRequest: [function (data) {
            // form-dataQsaxios
             data = Qs.stringify({});
             return data;
             console.log(data)
        }],

        transformResponse: [function (data) {
            // 

            return data;
        }],

        // 
        headers: {
            "Authorization": sessionStorage.obj,
            "Content-Type":"application/x-www-form-urlencoded;charset=UTF-8"
        },

        //parameter
        params: {
            timestamp: Date.parse(new Date()) / 1000
        },

        withCredentials:true,

        //postaxios.post(url,{},config);
        data: data,

        //
        timeout: 5000,
        //
        responseType: "json", // default
    }
    return axios.post(url, data, this.config)
}

}

call the interface on the page:

selectpriceDate = () = > {

    let url="api/notice/list"
    let form={
        pageNo: "1",
        pageSize: "12",
        type:null
    }
    ajax.post(url, form)
        .then(function (res) {
            console.log(res)
        })
        .catch(function (err) {
            console.log(err)
        })
}




:








your post method defines that the two this.config; you use are not one config, and the error message also indicates that


your return axios.post (url, data, this.config) this.config may not be the same thing as you expect to use the config variable defined internally by post .

Menu