Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mall-webview
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
frontend
mall-webview
Commits
490e0ef6
Commit
490e0ef6
authored
Apr 06, 2021
by
wykolor
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/2021_03_12_bonus' of dev.jiuaoedu.com:wykolor/GeekBonusH5…
Merge branch 'feature/2021_03_12_bonus' of dev.jiuaoedu.com:wykolor/GeekBonusH5 into feature/2021_03_12_bonus
parents
9345359e
5317fc5e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
http.ts
src/server/http.ts
+24
-1
No files found.
src/server/http.ts
View file @
490e0ef6
import
axios
,
{
AxiosRequestConfig
}
from
"axios"
;
import
Cookies
from
'js-cookie'
;
import
{
Toast
}
from
"vant"
;
import
{
unref
}
from
"vue"
;
import
router
from
"../router"
;
const
instance
=
axios
.
create
({
headers
:
{
'content-type'
:
'application/json;charset=UTF-8'
,
...
...
@@ -41,9 +43,30 @@ const instance = axios.create({
// }
// }
let
globalToken
:
string
|
null
=
null
;
// 拦截器 在请求之前拦截
instance
.
interceptors
.
request
.
use
(
(
config
:
AxiosRequestConfig
)
=>
{
const
route
=
unref
(
router
.
currentRoute
);
let
token
=
route
.
query
.
token
;
token
=
Array
.
isArray
(
token
)
?
token
[
0
]
:
token
;
// refresh token
if
(
token
&&
token
!==
globalToken
)
{
globalToken
=
token
;
}
if
(
globalToken
)
{
const
pre
=
config
.
headers
||
{};
return
{
...
config
,
headers
:
{
...
pre
,
Authorization
:
`Bearer
${
globalToken
}
`
}
};
}
return
config
;
},
error
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment