跨域解决方案

express服务器:

在路由前面添加如下代码即可:

app.all('*', function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*');
  res.header('Access-Control-Allow-Headers', 'Content-Type');
  res.header('Access-Control-Allow-Methods', '*');
  res.header('Content-Type', 'application/json;charset=utf-8');
  next();
});

 

posted @ 2020-10-10 14:39    阅读(105)  评论(0编辑  收藏  举报