Commit 8551790b by caoyanzhi

update: 更新请求封装

parent 319eb4bd
......@@ -7,7 +7,9 @@ export default function getFetch(api, baseUrl) {
let opt = api[key];
if (typeof opt === 'string') opt = { url: opt };
opt.url = `${baseUrl}${opt.url}`;
api[key] = params => request(opt, params);
// requestConfig提供请求发起之前动态设置axios配置的能力
// requestConfig的所有属性同request.js的opt参数
api[key] = (params, requestConfig) => request(opt, params, requestConfig);
});
return api;
}
......@@ -16,7 +16,7 @@ import { origin, succCode, notAuthCode } from '@/config/index.js';
axios.defaults.baseURL = origin;
axios.defaults.withCredentials = true;
const request = (opt, params) => {
const request = (opt, params, config) => {
params = Object.assign({}, params);
opt = Object.assign({}, opt);
let requestConfig = {
......@@ -33,7 +33,7 @@ const request = (opt, params) => {
// 设置headers
headers: {}
};
requestConfig = Object.assign(requestConfig, opt);
Object.assign(requestConfig, opt, config);
if (requestConfig.useFormData) params = qs.stringify(params);
switch (requestConfig.method.toLowerCase()) {
case 'get':
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment