希望无论是get还是post请求,都会携带userID信息。所以就把post请求的统一参数写在了config.data里,get的统一参数写在了get里。但是!!问题来了, ...config.params 并不会合并参数。具体代码如下。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); });具体使用: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); });},
添加回答
举报
0/150
提交
取消