axios get / post request

五:axios:

        axios并不是vue插件,所以不能使用Vue.use(),所以只能在每个需要发送请求的组件中即时引入。为了解决这个问题,可以在引入 axios 之后,通过修改原型链,来更方便的使用。

main.js中引入:import axios from 'axios'; 使用原型:Vue.prototype.axios = axios

设置默认url:axios.defaults.baseURL ="http://" + hostName;

设置携带cookie:axios.defaults.withCredentials =true;

get请求:  axios({

url:"/get",

method:"get",

params:{

key1:value1});

post请求:axios({

url:"/post",

method:"post",

data:{

xxx}

});



作者:ZhouYanXu55
链接:https://www.jianshu.com/p/ddd769c7a530
來源:简书
简书著作权归作者所有,任何形式的转载都请联系作者获得授权并注明出处。

猜你喜欢

转载自blog.csdn.net/LanSeTianKong12/article/details/84136777