我使用 CLI 创建了一个 VueJs 页面。我想在没有安装 Vue CLI 或 Node 的情况下向其他人展示它。就像您通常在浏览器中打开 .html 文件一样,我想在构建后打开 index.html 文件。
当我打开该文件时,我在控制台中看到一个空白页面,其中包含 404 错误消息。我拿了这些文档
https://cli.vuejs.org/guide/deployment.html#general-guidelines https://cli.vuejs.org/guide/deployment.html#general-guidelines
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
并添加了mode: "history",
到我的路由器对象。使用 Vue CLI 构建项目后,我设置了一个简单的 Node 服务器
const http = require('http');
const server = http.createServer();
const fs = require('fs');
const port = 3000;
server.on('request', async (req, res) => {
const htmlContent = fs.readFileSync('./index.html', 'utf-8');
res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
});
res.end(htmlContent);
});
server.listen(port, err => {
console.log(`server is listening on ${port}`)
})
运行服务器时我调用http://localhost:3000/
并得到一个有两个错误的空白页面
我缺少什么?