axios基本请求格式 POST、GET

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/zc_ad/article/details/85296036

设置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);
})


 

猜你喜欢

转载自blog.csdn.net/zc_ad/article/details/85296036