个人笔记,仅供参考。
1.GET请求
fetch(
`https://...?params=params¶ms1=params1...`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
"Authori-Zation": `Bearer ${localStorage.getItem("token")}`,
},
}).then((resp) => resp.json())
.then(data => {
//解析 {data}
});
2.POST请求
fetch("https://...",{
method:"POST",
headers:{
"Content-Type": "application/json",
},
body: JSON.stringify({
account:acc,
password:pwd,
}),
})
.then(resp=>resp.json())
.then(({data})=>{
console.log(data);
});