Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/simon-he95/vaxios
https://github.com/simon-he95/vaxios
Last synced: 10 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/simon-he95/vaxios
- Owner: Simon-He95
- Created: 2022-07-29T07:43:32.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T15:00:38.000Z (11 months ago)
- Last Synced: 2024-10-12T21:06:58.270Z (24 days ago)
- Language: TypeScript
- Size: 214 KB
- Stars: 4
- Watchers: 0
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
English | 简体中文
本文是 [simon-js-tool] 的附加 vAxios 文档 (https://www.npmjs.com/package/simon-js-tool).
## 更多
- Export function [exports-function](https://github.com/SimonHe1995/exportsFunction)
- threejs [@simon_he/s-three](https://github.com/SimonHe1995/sThree)
- Echarts [@simon_he/s-chart](https://github.com/SimonHe1995/sCharts)
- numsWheel [@simon_he/nums-wheel](https://github.com/SimonHe1995/numsWheel)## vAxios
- 基于axios的封装
- 重复的请求上一次会被自动取消
- 所有的请求都可以像post请求一样使用post(url, data, config)方式
```js
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')
})
```