【发布时间】:2020-01-31 12:07:13
【问题描述】:
我使用 CLI 创建了一个新的 vue 项目并想要部署它。基于此文档
https://router.vuejs.org/guide/essentials/history-mode.html#html5-history-mode
我将历史模式添加到路由器。运行npm run build 后,我将示例代码用于静态本机节点服务器
https://router.vuejs.org/guide/essentials/history-mode.html#example-server-configurations
const http = require('http')
const fs = require('fs')
const httpPort = 3000
http.createServer((req, res) => {
fs.readFile('../base/index.html', 'utf-8', (err, content) => {
if (err) {
throw err;
}
res.writeHead(200, {
'Content-Type': 'text/html; charset=utf-8'
})
res.end(content)
})
}).listen(httpPort, () => {
console.log('Server listening on: http://localhost:%s', httpPort)
})
所以当导航到localhost:3000 时,vue 项目似乎可以正确加载
但我有一个空白页,有两个错误
当我点击这些 js 文件时,它会显示 index.html 文件的内容。显然js是无法理解这个html内容的。我该如何解决这个问题?
【问题讨论】:
标签: javascript node.js vue.js vue-cli vue-cli-3