【发布时间】:2020-04-13 14:38:27
【问题描述】:
我知道有很多这类问题,但我不明白为什么dashboard.html 找不到appclient.js,但index.html 可以找到appclient.js。
我收到错误消息:GET http://localhost:3000/dashboard/js/appclient.js net::ERR_ABORTED 404 (Not Found)
app.js
// /login redirects the client to /dashboard/:uid if correctly authenticated
app.route("/login")
.get((req,res) => {
res.sendFile('./public/index.html', {root: __dirname})
})
app.route("/dashboard/:uid")
.get((req,res) => {
res.sendFile('./public/dashboard.html', {root: __dirname})
})
app.use(express.static('public'))
index.html
<!DOCTYPE html>
<html lang="de">
<head>
<script type="module" src="js/appclient.js" defer></script>
</head>
<body>
<myapp>
<h1> {{ title }} </h1>
</myapp>
</body>
</html>
dashboard.html
<!DOCTYPE html>
<html lang="en">
<head>
<script type="module" src="js/appclient.js" defer></script>
<title>Dash</title>
</head>
<body>
<h1>dash</h1>
</body>
</html>
appclient.js
import Vue from './lib/vue.esm.browser.js'
import VueResource from './lib/vue-resource.esm.js'
Vue.use(VueResource);
const myApp = new Vue({
name: "myapp",
el: ' myapp',
data: { //
title: "Hello World!",
}
})
【问题讨论】:
-
Dashboard.html 在localhost:3000/dashboard/js 查找.js。这也是仪表板路线的终点。请考虑阅读 express、vue 等的文档。更多。您没有按预期使用应用程序的任何部分...
标签: javascript express vue.js