1.Axios中文网网址
Axios中文文档 | Axios中文网 (axios-http.cn)
2.引入Axios的js文件
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
3.使用Axios发送请求
method:请求方法, 如: GET/POST
url:请求路径 必须写
data:请求数据 如果要传递参数则填写
then是成功回调函数,catch是失败回调函数
示例:
let book = {
name: 'axios快速入门',
category: '前端',
time: '2024-01-23',
state: '草稿'
}
axios({
method:'post',
url:'http://localhost:8080/book/save',
data:book
}).then(result=>{
//处理请求成功的数据
console.log(result.data);
}).catch(err=>{
//处理请求失败的数据
console.log(err);
});
4.Axios另一种书写格式
格式:axios.method(url [, data[, config]])
示例:
axios.post('http://localhost:8080/book/save', book).then(result => {
//处理请求成功的数据
console.log(result.data);
}).catch(err => {
//处理请求失败的数据
console.log(err);
});