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

前台使用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();
  }
});

结果显示是:

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

【热门文章】
【热门文章】