修改request,可自定contentType
This commit is contained in:
parent
3f85de1f93
commit
023564304c
|
@ -20,12 +20,12 @@ function findRule(name) {
|
|||
}
|
||||
|
||||
const request = async (args) => {
|
||||
let rule = findRule(args.api || '');
|
||||
const rule = findRule(args.api || '');
|
||||
if (JSON.stringify(rule) === "{}") {
|
||||
throw "找不到API:" + args.api;
|
||||
}
|
||||
|
||||
let query = (args.query) ? '?' + args.query : '';
|
||||
const query = (args.query) ? '?' + args.query : '';
|
||||
|
||||
if (typeof rule.auth !== "undefined" && rule.auth === true && !$store.state.user.token) {
|
||||
$store.commit("user/showLoginModal", true);
|
||||
|
@ -36,20 +36,18 @@ const request = async (args) => {
|
|||
title: "加载中"
|
||||
});
|
||||
|
||||
const headers = {
|
||||
"XX-Wxapp-AppId": prototype.$config.appId,
|
||||
'XX-Token': $store.state.user.token,
|
||||
'XX-Device-Type': 'wxapp',
|
||||
};
|
||||
const contentType = (args.contentType) ? args.contentType : 'application/json';
|
||||
|
||||
const [error, response] = await uni.request({
|
||||
url: prototype.$config.root + rule.url + query,
|
||||
method: rule.method || 'post',
|
||||
data: args.data,
|
||||
header: {
|
||||
"XX-Wxapp-AppId": prototype.$config.appId,
|
||||
'XX-Token': $store.state.user.token,
|
||||
'XX-Device-Type': 'wxapp',
|
||||
'X-Requested-With': 'XMLHttpRequest',
|
||||
'content-type': 'application/x-www-form-urlencoded',
|
||||
...headers
|
||||
'content-type': contentType,
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue