我是 NodeJs 新手,已经三天了,因为我试图通过 Express 在生产模式下运行 Vue 应用程序,由于某种原因它没有完成,我有一个带有 Bootstrap 4 的 Vue CLI3 设置。当我运行开发模式下的应用程序使用npm run serve
,它渲染得非常好。但当我尝试使用 server.js 文件运行它时它不会被渲染
下面是我的 server.js 代码
const express = require('express');
const port = process.env.PORT || 5000;
let app = express();
app.use(express.static(__dirname + "/dist/"));
app.get("*", (req, res) => {
res.sendfile(__dirname + '/dist/index.html');
});
app.listen(port, () => {
console.log('Listening on port ' + port)
});
我什至更换了 res.sendfile(__dirname + '/dist/index.html');
与 res.send({response message})
获取在浏览器中呈现的消息,但它会将相同的错误记录到控制台。
agian 使用 npm run serve
运行该应用程序时运行良好。有人知道这里发生了什么事吗?
最佳答案
检查是否有任何带有空 <script>
的组件标签。只需删除那些空标签即可。这解决了我的问题
关于node.js - NodeJs/Express Vue CLI3 应用程序错误无法设置未定义的属性渲染,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52411899/