@simon_he/v-axios
TypeScript icon, indicating that this package has built-in type declarations

0.0.7 • Public • Published

@simon_he/v-axios

NPM version

Docs

English | 简体中文

本文是 [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')
})

Readme

Keywords

Package Sidebar

Install

npm i @simon_he/v-axios

Weekly Downloads

3

Version

0.0.7

License

MIT

Unpacked Size

8.17 kB

Total Files

5

Last publish

Collaborators

  • simon_he