// fetch 类似 XMLHttpRequst 请求和响应 // 1 新 技术 // 2 功能 和 XMLHttpRequst 一样 // 3 用法 简单 fetch axios(用得最多) 拦截器 - 基地址 // * /
// 1 get请求
fetch('http://www.itcbc.com:3006/api/getbooks')
.then((result) => {
return result.json(); // 固定搭配 表示 把响应结果转成json 来使用
})
.then(result => {
console.log(result);
})
2 post 请求
fetch('url', {
method: 'POST', // 请求类型
headers: {
'Content-Type': 'application/json', // 设置内容
},
body: JSON.stringify(data), // post请求的参数部分
});