From 023564304c450516750160b4eab3e917abe8f41b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?TOP=E7=B3=AF=E7=B1=B3?= <1130395124@qq.com> Date: Thu, 9 Mar 2023 16:54:23 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9request=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E8=87=AA=E5=AE=9AcontentType?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/request.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/core/request.js b/src/core/request.js index 0e8e88c..f7a3800 100644 --- a/src/core/request.js +++ b/src/core/request.js @@ -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, } });