1.axios发送get请求,如果有要携带参数
axios.get(url,{
params:{name:‘zs’}
}
)
2.发送post请求,axios.post(url,data)
3.delete删除
//直接从url里面删除
axios.delete('/data.json',{
params:{
id:12
}
}).then((res)=>{
console.log(res)
})
axios.delete('/data.json',{
data:{
id:12
}
}).then((res)=>{
console.log(res)
})
参数配置方法
axios.defaults.基本配置方法(baseurl等)
请求拦截器
axios.interceptors.request.use(
config=>{
//在发送请求前做些什么
return config
},
err=>{
// 在请求错误的时候做些什么(此处错误,请求没有到后端)
return Promise.reject(err)//这里返回一个promise对象
}
)