1.GET:用域获取数据
2.POST:用于提交数据
3.PUT :更新数据(吧所有数据推送到后端)
4.PATCH:更新数据(只推送修改的数据到后端)
5.DELETE:删除数据
一个简单的请求



axios({
method:'GET',
url:'/data.json',
params:{
//传递的参数
id:12
//在URL中为
//http://localhost:8080/data.json?id=12
}
})
.then(res=>{
console.log(res);
})
.catch(err=>{
console.log(err);
})
//当然这个也可以这样写
/*let request=axios.create({
baseURL:"http://localhost:8080",
timeout:1000
})
request.get("/data.json").then.....*/
POST方法提交
axios({
method:'POST',
url:'/post',
data:data
//提交的数据用data表示
})
.then(res=>{
console.log(`res ->${res}`);
})
.catch(err=>{
console.log(err);
})
PUT请求和PATCH请求
axios({
method:'PUT',
url:'/put'
})
.then(res=>{
console.log(`res ->${res}`);
})
.catch(err=>{
console.log(err);
})
axios({
method:'PATCH',
url:'/patch'
})
.then(res=>{
console.log(`res ->${res}`);
})
.catch(err=>{
console.log(err);
})
这里params和data的区别就是params是在URL进行参数传递的,而data不是
博客介绍了常见HTTP请求方法,包括GET用于获取数据、POST用于提交数据、PUT更新全量数据、PATCH更新部分数据、DELETE删除数据,还提及一个简单请求示例,以及POST方法提交,同时说明了PUT和PATCH请求中params和data在参数传递上的区别。
1121

被折叠的 条评论
为什么被折叠?



