0.0.7 • Published 3 years ago

@simon_he/v-axios v0.0.7

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

本文是 simon-js-tool 的附加 vAxios 文档 (https://www.npmjs.com/package/simon-js-tool).

更多

vAxios

  • 基于axios的封装
  • 重复的请求上一次会被自动取消
  • 所有的请求都可以像post请求一样使用post(url, data, config)方式
const axios = vAxios({
  baseURL: 'http://localhost:3000',
  timeout: 1000,
  headers: {
    'Content-Type': 'application/json'
  },
  interceptor: {
    request(config) {
      console.log(config)
      return config
    },
    response(response) {
      console.log(response)
      return response
    },
    requestError(error) {
      console.log(error)
      return Promise.reject(error)
    },
    responseError(error) {
      console.log(error)
      return Promise.reject(error)
    }
  }
})

axios.get('/api/get', { // get请求可以像其他请求一样传参
  id: 1,
  name: '22'
}, {
  headers: {
    'Content-Type': 'application/json'
  }
}).then((res) => {
  console.log(res)
}).catch((err) => {
  console.log(err)
}).finally(() => {
  console.log('finally')
})

axios.post('/api/get', {
  id: 1,
  name: '22'
}, {
  headers: {
    'Content-Type': 'application/json'
  }
}).then((res) => {
  console.log(res)
}).catch((err) => {
  console.log(err)
}).finally(() => {
  console.log('finally')
})
0.0.7

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

3 years ago

0.0.1

3 years ago