npm 安装 axios
npm install axios -s
axios 发送请求 usage
axios内置了promise模块
const axios = require('axios');
axios.get('/user?ID=12345')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
console.log('finally')
});
传参方式也可为对象形式
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
console.log('finally')
});
使用async await
async function getUser() {
try {
const response = await axios.get('/user?I