- axios的get语法
axios.get("/list") // 请求路径和请求参数拼接
.then(function(resp){
// 成功回调函数
})
.catch(function(){
// 失败回调函数
})
// 参数较多时,可以通过params来传递参数
axios.get("/item/category/list", {
params:{
pid:0
}
})
.then(function(resp){})// 成功时的回调
.catch(function(error){})// 失败时的回调
- axios的post语法
axios.post("/student",{
name:"zs",
age:21
}).then(function(resp){
}).catch(function(error){
})
- axios发送通用方法
this.$http({
method: this.isEdit ? 'put' : 'post',
url: '/item/brand',
data: params
}).then(() => {
})
.catch(() => {
});
}
- axios的全局配置
axios.defaults.baseURL = "http://api.leyou.com" // 设置axios的基础请求路径
axios.defaults.timeout = 2000; //设置请求超时时间