前台使用isomorphic-fetch获取数据时显示type:'cors',使用superagent就不会

新手上路,请多包涵

前台使用isomorphic-fetch获取数据时显示type:'cors'

require('es6-promise').polyfill();
require('isomorphic-fetch');
fetch('http://localhost:3004/find').then(function(response) {
    console.log(response)
})

后台已经设置了同意跨域了


app.all('*',function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , yourHeaderFeild');
  res.header('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');

  if (req.method == 'OPTIONS') {
    res.send(200); /让options请求快速返回/
  }
  else {
    next();
  }
});

结果显示是:

clipboard.png

求解 是fetch需要设置头信息吗,使用superagent的时候就可以。

阅读 7.5k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题