1. 程式人生 > >axios基本請求格式 POST、GET

axios基本請求格式 POST、GET

設定global的axios引數

##axios 
axios.defaults.baseURL = 'http://localhost:7001/micro';
axios.defaults.headers.common['school_id'] = "1005";
axios.defaults.headers.post['content-Type'] = 'application/json;charset=UTF-8';   //post引數傳遞的json形式

1.GET請求

//params:{"page_size":3},此引數會拼接到url上,最後形式為:/items?page_size=3
axios.get("/items",{params:{"page_size":3}}).then(res=>{   
                console.log(res);
            }).catch(err=>{
                console.log(err);
            })

2.POST請求

//{"is_show": 0, "name": "盡力金", "type": 0} 是以json的形式傳輸的
axios.post("/item",
    {"is_show": 0, "name": "盡力金", "type": 0}
).then(res=>{
    console.log(res);
}).catch(err=>{
    console.log(err);
})