Skip to content

moriwang/axios-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CancelToken

  • Cache requests
  • Cancel duplicate requests
  • Error handling

How to use

don't use in production, this repo is just for study purpose.

Define Actions for api

See url.js.

sampleAPI: {
  requestURL(path) {
    return `sampleAPI/ + ${path}`
  },
  onSuccess: 'Get Request Success',
  onFail: 'Get Request Fail'
},

Support Methods

  • get(action, parameter, [path])
  • post(type, action, parameter, [path])
    • type: json or qs

Sample Code

get('sampleGet', parameters, path)
  .then(res => {
    let [res, message] = res
    // do something
  })
  .catch(err => {
    let [err, message] = err
    // do something else
  })

post('json', 'samplePost', parameters, path)

About

axios encapsulation study

Resources

License

Stars

Watchers

Forks