1)發(fā)起get請求
? ? ? ?axios.get("/user?id=123").then(function(response){
? ? ? ? ? ? ? ? ? ? ? ? }).catch(function(e){
? ? ? ? ? ? ? ? ? ? ? ? })
? ? ? ? axios.get('/user',{ params:{id:123} }).then(function(){}).catch(function(){
? ? ? ? ? ? ? ? ? ? ? ? })
2)? 發(fā)起post請求
? ? ? ? ?axios.post("/user",{first:"ww",last:"sss"}).then().catch();
3)? 同時(shí)發(fā)起多個(gè)請求
? ? ? ?function? getUserAccount(){return axios.get("? ")}
? ? ? ?function? ?getUserPer(){return axios.get("? ")};
? ? ? axios.all([getUserAccount(),getUserPer()]).then(?
? ? ? ? ? ? ? ? ? ? ? ? ? ? axios.spread(function(acct,per){
? ? ? ? ? ? ? ? ? ? ? ? ? ? ?})
? ? ? ? )
4)? ?導(dǎo)入相關(guān)配置發(fā)起請求
? ? ? ?axios({ method:"post",url:"/user/123",data:{first:"ss",sec:"ddd"} } )
5)? ?創(chuàng)建一個(gè)擁有通用配置的axios實(shí)例
? ? ? ? var? instance =axios.create({
? ? ? ? ? ? ? ? ? baseURL:'https://some-domain.com/api/',
? ? ? ? ? ? ? ? ? timeout:1000,
? ? ? ? ? ? ? ? ?headers: {'X-Custom-Header':'foobar'}
? ? ? ? })