Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
walk_daka_h5
Overview
Overview
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
穆启卓
walk_daka_h5
Commits
50e56559
Commit
50e56559
authored
Apr 03, 2019
by
Caiyijun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change
parent
8435b1cc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
17 additions
and
17 deletions
+17
-17
fetch.js
src/components/axios/fetch.js
+17
-17
No files found.
src/components/axios/fetch.js
View file @
50e56559
import
axios
from
'axios'
;
//引入axios
import
axios
from
'axios'
//引入axios
export
function
fetch
(
options
)
{
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
if
(
!
window
[
'userData'
])
{
let
user_data_str
=
localStorage
.
getItem
(
'walk_userData'
)
;
let
user_data_str
=
localStorage
.
getItem
(
'walk_userData'
)
if
(
user_data_str
)
{
window
[
'userData'
]
=
JSON
.
parse
(
user_data_str
)
;
window
[
'userData'
]
=
JSON
.
parse
(
user_data_str
)
}
}
if
(
!
window
[
'userData'
])
{
localStorage
.
setItem
(
'last_url'
,
location
.
hash
.
slice
(
1
))
;
location
.
replace
(
'#/Author'
)
;
localStorage
.
setItem
(
'last_url'
,
location
.
hash
.
slice
(
1
))
location
.
replace
(
'#/Author'
)
}
}
return
new
Promise
((
resolve
,
reject
)
=>
{
...
...
@@ -18,28 +18,28 @@ export function fetch(options) {
//所有的请求都会带上这些配置,比如全局都要用的身份信息等。
headers
:
{
'Content-Type'
:
'application/json'
,
'Authorization'
:
process
.
env
.
NODE_ENV
===
'production'
?
(
window
[
'userData'
]
?
window
[
'userData'
].
token
:
''
)
:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJvcGVuX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsInVuaW9uX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsImV4cCI6MTU1NDQ1NzU3Mn0.ehCAENl8zjdMyF4y44Z2-XEascaDhEbUF3BaNsWbfY8"
'Authorization'
:
process
.
env
.
NODE_ENV
===
'production'
?
(
window
[
'userData'
]
?
window
[
'userData'
].
token
:
''
)
:
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoiMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAiLCJvcGVuX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsInVuaW9uX2lkIjoiMTExMTExMTExMTExMTExMTExMTExMTExMTExMSIsImV4cCI6MTU1NDQ1NzU3Mn0.ehCAENl8zjdMyF4y44Z2-XEascaDhEbUF3BaNsWbfY8"
// 'token_in_header': global_.token,//token从全局变量那里传过来
},
timeout
:
30
*
1000
// 30秒超时
})
;
})
instance
(
options
)
.
then
(
response
=>
{
//then 请求成功之后进行什么操作
console
.
log
(
'raw response'
,
response
);
response
.
data
[
'date'
]
=
response
.
headers
.
date
;
resolve
(
response
.
data
);
//把请求到的数据发到引用请求的地方
console
.
log
(
'raw response'
,
response
)
response
.
data
[
'date'
]
=
response
.
headers
.
date
resolve
(
response
.
data
)
//把请求到的数据发到引用请求的地方
})
.
catch
(
error
=>
{
console
.
log
(
'请求异常信息:'
,
error
);
console
.
log
(
'请求异常信息:'
,
error
)
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
if
(
error
.
response
.
status
==
401
)
{
localStorage
.
setItem
(
'last_url'
,
location
.
hash
.
slice
(
1
));
localStorage
.
setItem
(
'walk_userData'
,
''
);
location
.
replace
(
'#/Author'
);
localStorage
.
setItem
(
'last_url'
,
location
.
hash
.
slice
(
1
))
localStorage
.
setItem
(
'walk_userData'
,
''
)
location
.
replace
(
'#/Author'
)
}
else
{
reject
(
error
);
reject
(
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