在app.js里面写
//跨域
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With,X_Requested_With,Content-Type");
// res.header("Content-Type", "application/json;charset=utf-8"); //注,如果包括页面等非json, 不要这句
next();
});
//出现cors的问题时
app.use(cors({
origin: ['http://localhost:3000'], // 所要允许跨域的ip
methods: ['GET', 'POST'],//请求头get,post,delete.put
alloweHeaders: ['Conten-Type', 'Authorization']
}));