-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Axios post bugs All In One #107
Labels
Comments
solution
import axios from '@/utils/http.js';
// 保存创意
const axiosUtils = (url = '', params = {}, type = 'get') => {
if(!url) {
throw new Error('❌ API URL 不可为空!');
// return;
}
// switch...case
if(type === 'post') {
// application/x-www-form-urlencoded ✅
return axios.post(url, params);
}
if(type === 'get') {
// multipart/form-data ✅
return axios.post(url, {params});
}
if(type === 'put') {
// multipart/form-data ✅
return axios.post(url, {params});
}
}; |
改写 Axioslet oldTimestamp = null;
// 每次请求都带上token
instance.interceptors.request.use(config => {
// // todo 为了减少测试的报错信息,暂时过滤工作表下的所有拦截逻辑,但上线前必须去掉
// const isTable = window.location.href.indexOf('/table-2') > -1;
// if (!pendingUrlWhitelist.includes(config.url) && !isTable) {
if (!pendingUrlWhitelist.includes(config.url)) {
removePending(config);
addPending(config);
}
config = requestWithToken(config);
// 处理 post|delete|put 请求,以formdata形式传参
if (['post', 'delete', 'put'].includes(config.method)) {
for (let key in config.data) {
if (config.data.hasOwnProperty(key) && config.data[key] === null || config.data[key] === undefined) {
delete config.data[key];
}
}
// 不传 header 默认, query string
if (!config.headers.hasOwnProperty('Content-Type')) {
config.data = qs.stringify(config.data);
config.headers['Content-Type'] = 'application/x-www-form-urlencoded';
} else {
// post json
}
}
oldTimestamp = performance.now();
return config;
}, error => {
oldTimestamp = performance.now();
return Promise.reject(error);
}); |
demosaxios post
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Axios post bugs All In One
application/x-www-form-urlencoded
multipart/form-data
application/json
The text was updated successfully, but these errors were encountered: