Axios 基本使用
Axios 的引入
中文网站:https://www.kancloud.cn/yunye/axios/234845
安装: https://unpkg.com/axios/dist/axios.min.js
GET方式的请求
axios.get("http://localhost:8989/user/findAll").then(function(response){
console.log(response.data);
}).catch(function(err){
console.log(err);
});
POST方式请求
axios.post("http://localhost:8989/user/save",{
username:"xxxx",
age:23,
email:"xxxx",
phone:11111111111
}).then(function(response){
console.log(response.data);
}).catch(function(err){
console.log(err);
});
创建配置实例
var instance = axios.create({
baseURL:"http://localhost:8080", //基础url
timeout: 5000 //超时时间
});
// instance.delete("/users/1").then(function (response){
// console.log(response);
// console.log(response.data);
// }).catch(function (error) {
// console.log(error);
// })
拦截器
//请求拦截器 获取请求配置
// instance.interceptors.request.use(function (config) {
// return config;
// })
//
// //响应拦截器
// instance.interceptors.response.use(function (response) {
// return response;
// })