使用fetch发送请求
//直接调用fetch函数
fetch(‘http://127.0.0.1:8008/server?a=2’,{
method:‘POST’,
headers:{
aa:1111,
bb:12313213131
},
//请求体
body: ‘username=admin&password=admin’
}).then(a=>{
//返回响应体的text 如果服务器那边是一个json对象就写成return a.json()
return a.text()
}).then(b=>{
console.log(b);
})
这个用的少不过多学没坏处