axios
我的ai
https://www.coze.cn/store/agent/7431754345064005683?bid=6ecb2bce0901k
官网文档
https://www.axios-http.cn/docs/example
get参数形式
get请求的参数传递形式
axios.get('http://localhost:8080/user/findById', {
params: {
id: 1
}
})
相当于
axios.get('http://localhost:8080/user/findById?id=1')
示例
const axios = require('axios');
// 向给定ID的用户发起请求
axios.get('/user?ID=12345')
.then(function (response) {
// 处理成功情况
console.log(response);
})
.catch(function (error) {
// 处理错误情况
console.log(error);
})
.finally(function () {
// 总是会执行
});
// 上述请求也可以按以下方式完成(可选)
axios.get('/user', {
params: {
ID: 12345
}
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.finally(function () {
// 总是会执行
});
// 支持async/await用法
async function getUser() {
try {
const response = await axios.get('/user?ID=12345');
console.log(response);
} catch (error) {
console.error(error);
}
}