This article is documentation that describes the encapsulated utility functions @simon_he/v-axios
peculiarity: High scalability, flexible and convenient calling
More
- Common functions lazy-js-utils
- Export functions exports-functions
- Threejs simplistic s-three
- numsWheel component s-nums-wheel
- Echarts simplistic s-charts
Instructions for use
npm i @simon_he/v-axios # install
import {
vAxios,
...
} from '@simon_he/v-axios' # Ingestion on demand
Directory structure
00vAxiosAxios encapsulates the function
vAxios
- Axios-based packaging
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', { // The get request can be passed across like any other request
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')
})