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, } });