<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<script src="./js/axios.js">
</script>
<script>
/* axios
.请求方式(url)
.then((res) => {
获取数据res.data
})
.catch((err) => {}) */
//get查询
axios
.get('http://localhost:8888/brands')
.then((res) => {
/* console.log(res) */
const {
status,
data
} = res
if (status === 200) {
console.log(data)
}
})
.catch((err) => {
})
//post数据
/* axios.post(url,"要添加的数据") */
axios
.post('http://localhost:8888/brands', {
name: 'abcdf',
date: new Date()
})
.then((res) => {
console.log(res.status);
})
//put数据
axios.put('http://localhost:8888/brands/5', {
name: 'xxx',
date: new Date()
})
.then((res) => {
console.log(res.status);
})
//delete
axios.delete('http://localhost:8888/brands/6')
.then((res) => {
console.log(res.status);
})
</script>
</body>
</html>