编程杂谈
说明Axios是一个基于promise的HTTP库,可以用在浏览器和node.js中。相关请求引入:https://cdn.jsdelivr.net/npm/axios/dist/axios.min.jsGET请求精简(只有url,没有参数)axios.get(url).then(response=>{//请求成功console.log(response.data);}).catch(error=>{//请求失败,console.log(error);});完整参数axios.get(url,{//设置请求头信息,可以传递空值headers:{K:V,},//传递参数params:{K:V,},}).then(response=>{//请求成功console.log(response.data);}).catch(error=>{//请求失败,console.log(error);});POST请求qs库地址:https://cdn.bootcdn.net/ajax/libs/qs/3.0.0/qs.jsqs.stringify():将对象或者数组序列化成URL的格式qs.parse():将qs.stringify()序列化的对象或者数组转回去letdata={K:V}axios.post("api",qs.stringify(data),{headers:{'token':token}}).then(response=>{//请求成功letres=response.data;console.log(res);}).catch(error=>{//请求失败,console.log(error);});其他请求待更新