From 0c52c12c6c860d4b1b8c74a10e06f55164340d9c Mon Sep 17 00:00:00 2001 From: Gaoxs <704041637@qq.com> Date: Wed, 11 Nov 2020 23:33:39 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8D=E9=9C=80=E8=A6=81=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E7=9A=84=E6=8E=A5=E5=8F=A3,=E5=8F=96=E6=B6=88=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0Authorization=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/request.js | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/utils/request.js b/utils/request.js index 1147e3f..633ba54 100644 --- a/utils/request.js +++ b/utils/request.js @@ -42,7 +42,7 @@ fly.interceptors.response.use( handleLoginFailure(); return Promise.reject({ msg: "未登录", toLogin: true }); } - if (error.response.data.status == 5109) { + if (error.response.data.status == 5109) { uni.showToast({ title: error.response.data.msg, icon: "none", @@ -62,9 +62,16 @@ function baseRequest(options) { // 合并传参过来的 headers // 如果接口需要登录,携带 token 去请求 + options.headers = { - ...options.headers, - Authorization: "Bearer " + token + ...options.headers + } + + if (options.login === true) { + options.headers = { + ...options.headers, + Authorization: "Bearer " + token + } } // 如果需要登录才可访问的接口没有拿到 token 视为登录失效