mp_axios
v1.0.0
Published
webchat miniprogram axios
Downloads
2
Maintainers
Readme
mp_axios
wechat miniprogram simple version axios
Usage
npm install mp_axios
API
Reference axios https://github.com/axios/axios and see source code
import axios from 'mp_axios';
const http = axios.create({
baseURL: API_URL + '/api/',
headers: {
'post': { 'Content-Type': 'application/json; charset=utf-8' },
'put': { 'Content-Type': 'application/json; charset=utf-8' },
'patch': { 'Content-Type': 'application/json; charset=utf-8' }
}
});
// Response interception
http.interceptors.response.use(res => {
...Do something
return res;
}, err => {
...Do something
return Promise.reject(err);
});
// Request interception
http.interceptors.request.use(function (config) {
...Do something
return config;
}, function (error) {
return Promise.reject(error);
});
// Request cancel
cancel && cancel();
const res = await axios.post({
user_id: 123
}, {
headers: { ... },
cancelToken: new axios.CancelToken(
c => _cancel = c
)
});