修改request,可自定contentType

This commit is contained in:
TOP糯米 2023-03-09 16:54:23 +08:00
parent 3f85de1f93
commit 023564304c
1 changed files with 7 additions and 9 deletions

View File

@ -20,12 +20,12 @@ function findRule(name) {
} }
const request = async (args) => { const request = async (args) => {
let rule = findRule(args.api || ''); const rule = findRule(args.api || '');
if (JSON.stringify(rule) === "{}") { if (JSON.stringify(rule) === "{}") {
throw "找不到API" + args.api; 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) { if (typeof rule.auth !== "undefined" && rule.auth === true && !$store.state.user.token) {
$store.commit("user/showLoginModal", true); $store.commit("user/showLoginModal", true);
@ -36,20 +36,18 @@ const request = async (args) => {
title: "加载中" title: "加载中"
}); });
const headers = { const contentType = (args.contentType) ? args.contentType : 'application/json';
"XX-Wxapp-AppId": prototype.$config.appId,
'XX-Token': $store.state.user.token,
'XX-Device-Type': 'wxapp',
};
const [error, response] = await uni.request({ const [error, response] = await uni.request({
url: prototype.$config.root + rule.url + query, url: prototype.$config.root + rule.url + query,
method: rule.method || 'post', method: rule.method || 'post',
data: args.data, data: args.data,
header: { header: {
"XX-Wxapp-AppId": prototype.$config.appId,
'XX-Token': $store.state.user.token,
'XX-Device-Type': 'wxapp',
'X-Requested-With': 'XMLHttpRequest', 'X-Requested-With': 'XMLHttpRequest',
'content-type': 'application/x-www-form-urlencoded', 'content-type': contentType,
...headers
} }
}); });