1、特点:只需要关心请求方式是什么,而不需要关注于表示url
2、get:查询请求 - 200 post:上传新数据 - 201 put:修改 -200 delete:删除 - 200
GET:查 / POST:增 / PUT:改(需要具体的id)/ DELETE:删(需要具体的id)
上面返回的数字200和201表示对数据操作成功
3、模糊搜索/brands?name_like=关键字
<script src="axios.min.js"></script>
<script>
// 查询所有数据
axios
.get('http://localhost:3000/brands')
.then((res) =>{
console.log(res.status)
})
// 增加数据
axios
.post('http://localhost:3000/brands',{
name:"小猪1号",
date:new Date()
})
.then((res) =>{
console.log(res.status)
})
// 修改id为5的数据
axios
.put('http://localhost:3000/brands/5',{
name:"小猪2号",
date:new Date()
})
.then((res) =>{
console.log(res.status)
})
// 删除id为6的数据
axios
.delete('http://localhost:3000/brands/6')
.then((res) =>{
console.log(res.status)
})
// 模糊查询包含小猪的数据
axios
.get('http://localhost:3000/brands?name_like=小猪')
.then((res) =>{
console.log(res.data)
})
</script>
评论功能已关闭。