跨域报错 :
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3022' is therefore not allowed access.
按照网上方法 :在入口文件中添加了以下代码
// 解决跨域问题
// app.all('*', function(req, response, next) {
// //设置允许跨域的域名,*代表允许任意域名跨域
// response.header("Access-Control-Allow-Origin", "*");
// //允许的header类型
// response.header("Access-Control-Allow-Headers", "X-Requested-With");
// //跨域允许的请求方式
// response.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
// //设置响应头信息
// response.header("X-Powered-By",' 3.2.1')
// response.header("Content-Type", "application/json;charset=utf-8");
// next();
// });
最后解决 : 只是一个代码先后的问题 node代码从上往下执行