企业网站建设流程图,做信息流推广需要建立网站么,wordpress阅读量的统计,为什么做电影网站没有流量吗为了应对业务的复杂性#xff0c;提高前端的渲染能力#xff0c;故在项目中引入nodejs做中间层#xff0c;前端承接vue#xff0c;后端对接Java。
至于为什么这么搞#xff0c;网上有好多文章都在讨论#xff0c;可以说仁者见仁智者见智#xff0c;这里我们不在深究。 … 为了应对业务的复杂性提高前端的渲染能力故在项目中引入nodejs做中间层前端承接vue后端对接Java。
至于为什么这么搞网上有好多文章都在讨论可以说仁者见仁智者见智这里我们不在深究。
这里主要记录一下我在项目中尝试使用这种结构遇到的问题
1.前端的vue工程采用axios请求中间层node服务会遇到跨域问题
解决方法打开vue工程的index.js配置文件添加如下配置
assetsSubDirectory: static,
assetsPublicPath: /,
proxyTable: {/api: {target: http://localhost:3000,changeOrigin: true,pathRewrite: {^/api: }}
},
2.中间层使用axios请求后端接口时需要等待接口返回后在传递数据给前端这里就需要使用同步请求机制
解决方法采用 async, await 方式如下
var express require(express)
var router express.Router()
var http require(../config/http)router.get(/getFarmTargets, async (req, res, next) {console.log(进入请求)var result {}result.targets await http.get(/cim/cimInfos/survey?orgId1115).then(response response.data.code 0 ? response.data.data : null)result.introductions await http.get(/cim/introductions, { orgId: 1115 }).then(response response.data.code 0 ? response.data.data : null)console.log(回调外层2 JSON.stringify(result))res.json({code: 0,msg: ,data: result})next()
})
先记录到这儿未完待续......