初识axios
一般情况下最长用的axios请求是get请求和post请求
get请求:
问号拼接传递参数 axios.get("请求的地址url?传递的参数").then(function(res){console.log(res.data)}).catch(err=>{错误处理的代码})
或者
axios.get("请求的地址url",{
params:{
参数:参数值
......
}
}).then(function(res){console.log(res.data)}).catch(err=>{错误处理的代码})
post请求:
axios.post("请求的地址url",{
参数:参数值
...........
}).then(res=>{对返回的数据进行的操作}).catch(err=>{错误处理代码})
发送请求的时候也可以通过向axios传递相关配置来创建请求
axios({
method:"请求方法post/get",
url:"请求的地址url",
data:{
参数:参数值
}
})
同时发送多个axios请求
将不同的请求封装成不同的函数
axios.all([函数1(),函数2()]).then(axios.spred(function(形参1,形参2){对返回的数据进行操作})).catch(err=>{错误处理的代码})
浙公网安备 33010602011771号