Why is the axios unified configuration parameter invalid?

expect both get and post requests to carry userID information. So the unified parameters of post request are written in config.data, and the unified parameters of get are written in get.
but! Here"s the problem. .config.params does not merge parameters.
the specific code is as follows.

Axios.interceptors.request.use(
    (config) => {
        if ( config.method === "post" ) {
            if (sessionStorage.getItem("fwqAdmin")) {
                config.data = querystring.stringify({
                    userId: JSON.parse(sessionStorage.getItem("fwqAdmin")).userId,
                    ...config.data
                });
                console.log(config);
            }
        } else if ( config.method === "get" ) {
            if (sessionStorage.getItem("fwqAdmin")) {
                config.params = {
                    userId: JSON.parse(sessionStorage.getItem("fwqAdmin")).userId,
                    ...config.params
                };
            }
        }
        config.headers.Authorization = sessionStorage.getItem("fwqAdmin") ? JSON.parse(sessionStorage.getItem("fwqAdmin")).accessToken : "";
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject("" + error);
    }
);

specific use:

requestWxList() {
    let params = {
        pageNum: this.pageNav.curPage,
        pageSize: this.pageNav.pageSize
    };
    this.$http.get("/result/listSummarysPage",params)
        .then((res) => {
            console.log(res);
            this.tableData = res.data.data.items;
            this.pageNav.total = res.data.data.total;
        })
        .catch((err) =>{
            console.log(err);
        });
},
    
    
    
    
    
  

Mar.21,2021

Let me show you axios Source get the second parameter of the request is config
you treat params as config and upload config.params has no value

.


should call this.$http.get ('/ result/listSummarysPage', {params: params})


the old buddy upstairs has given the correct answer, but can only adopt one answer. Sorry. I hope the answer can help later people. No, no, no. Thank you

Menu