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);
});
},