node之express搭建服务渲染(一)
程序员文章站
2022-06-01 09:21:00
...
前提是已经搭建好初步express,参考https://blog.csdn.net/lbpro0412/article/category/7988872
然后,vue-cli搭建demo,接下来引入axios,参考:https://blog.csdn.net/lbpro0412/article/category/7995996
接口调用:
this.$ajax.get('http://localhost:3000/users').then((res)=>{
console.log(res,222222222222)
})
然而这个时候,页面报错了,错误如下
解决方法是
app.all('*', function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "X-Requested-With,Content-Type");
res.header("Access-Control-Allow-Methods","PUT,POST,GET,DELETE,OPTIONS");
next();
});