1.)使用
https://blog.youkuaiyun.com/mjzhang1993/article/details/72833095
2.)跨域问题
let myHeaders = new Headers({
'Access-Control-Allow-Origin':'*',
"Content-Type":'text/plain'
})
let url = "http://localhost:3000/posts";
fetch(url,{
method:'GET',
headers:myHeaders,
mode:'cors'
}).then(res=>{
console.log(res);
return res.text();
}).then(data=>{
console.log(data)
})
如果cors不行的话,改为no-cors
如果mode设置成:‘no-cors’请求时,reponse响应中type显示为opaque,则这时候该使用jsonp了。或者后端代理。