axios
GET 请求111
axios.get('/user?ID=12345')
.then(function (response) {
})
.catch(function (error)
});
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
})
.catch(function (error) {
});
POST 请求
axios.post('/user', {
firstName: 'Fred',
lastName: 'Flintstone'
})
.then(function (response) {
})
.catch(function (error) {
});
执行多个并发请求
function getUserAccount() {
return axios.get('/user/12345');
}
function getUserPermissions() {
return axios.get('/user/12345/permissions');
}
axios.all([getUserAccount(), getUserPermissions()])
.then(axios.spread(function (acct, perms) {
}));
通用请求方式
axios({
method: 'post',
url: '/user/12345',
data: {
firstName: 'Fred',
lastName: 'Flintstone'
}
})
.then(function (response) {
})
.catch(function (error) {
});
默认配置
axios.defaults.method = 'get',
axios.defaults.baseURL = 'http://localhost:3000',
axios.defaults.timeout = 3000
创建实例对象
let duanzi = axios.create({
baseURL:"https://api.apiopen.top",
timeout:3000
})
duanzi({ url:'/getJoke' }).then(res=>{ })