Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
mould-vuecli3
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
lhfe
mould-vuecli3
Commits
15fca70e
Commit
15fca70e
authored
Dec 02, 2020
by
lipengcheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: promise封装
parent
228e732a
Pipeline
#3098
failed with stages
in 0 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
6 deletions
+13
-6
index.js
src/api/index.js
+10
-6
index.js
src/plugins/axios/index.js
+3
-0
No files found.
src/api/index.js
View file @
15fca70e
...
...
@@ -31,12 +31,16 @@ function injectRequest(apiObj, axios) {
method
=
method
.
toUpperCase
()
requestMap
[
alias
]
=
(
dataOrParams
=
{},
instanceConf
=
{})
=>
{
const
keyName
=
[
'PUT'
,
'POST'
,
'PATCH'
].
includes
(
method
)
?
'data'
:
'params'
return
axios
({
method
,
url
,
// [keyName]: method === 'POST' ? qs.stringify(dataOrParams) : dataOrParams,
[
keyName
]:
dataOrParams
,
...
Object
.
assign
(
config
||
{},
instanceConf
)
return
new
Promise
((
resolve
,
reject
)
=>
{
axios
({
method
,
url
,
// [keyName]: methods === 'POST' ? qs.stringify(dataOrParams) : dataOrParams,
[
keyName
]:
dataOrParams
,
...
Object
.
assign
(
config
||
{},
instanceConf
)
})
.
then
((
res
)
=>
resolve
(
res
.
data
))
.
catch
((
err
)
=>
reject
(
err
))
})
}
})
...
...
src/plugins/axios/index.js
View file @
15fca70e
import
axios
from
'axios'
import
utils
from
'axios/lib/utils'
import
setConfig
from
'@/plugins/axios/axios.setConfig.js'
import
handleResponse
from
'@/plugins/axios/axios.handleResponse.js'
import
handleError
from
'@/plugins/axios/axios.handleError.js'
console
.
log
(
'utils.merge:'
,
utils
.
merge
)
// import store from '@/store/index'
// import router from '@/router/index.js'
// import { Message } from 'element-ui'
...
...
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