1)发起get请求
axios.get("/user?id=123").then(function(response){
}).catch(function(e){
})
axios.get('/user',{ params:{id:123} }).then(function(){}).catch(function(){
})
2) 发起post请求
axios.post("/user",{first:"ww",last:"sss"}).then().catch();
3) 同时发起多个请求
function getUserAccount(){return axios.get(" ")}
function getUserPer(){return axios.get(" ")};
axios.all([getUserAccount(),getUserPer()]).then(
axios.spread(function(acct,per){
})
)
4) 导入相关配置发起请求
axios({ method:"post",url:"/user/123",data:{first:"ss",sec:"ddd"} } )
5) 创建一个拥有通用配置的axios实例
var instance =axios.create({
baseURL:'https://some-domain.com/api/',
timeout:1000,
headers: {'X-Custom-Header':'foobar'}
})
网友评论