gpt4 book ai didi

vue.js - Vue 应用程序在通过 npm 的 serve 函数提供服务时工作,但在通过 golang net/http 包提供服务时出现空白页面

转载 作者:行者123 更新时间:2023-12-01 22:13:56 26 4
gpt4 key购买 nike

我有一个 Vuejs 应用程序,我试图通过 Golang 后端提供服务,该后端也将提供应用程序的 API。

当我通过“npm run build”和“serve -s dist”构建和运行 Vuejs 并转到静态服务器的位置时,一切正常。但是当我尝试通过 Golang 后端加载它时,即使加载了 index.html(通过检查浏览器中的源代码来验证),我也只是得到一个空白页面。

这种方法不可能吗?我对这一切都错了吗?

这是我通过 Golang 为“dist”文件夹提供服务的方式。

http.Handle("/", http.StripPrefix("/", http.FileServer(http.Dir(htmlFolder+"/dist/"))))

我的 index.html 文件:
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8>
<meta http-equiv=X-UA-Compatible content="IE=edge">
<meta name=viewport content="width=device-width,initial-scale=1">
<link rel=icon href=/favicon.ico>
<title>TestApp</title>
<link href=/css/app.52c62e82.css rel=preload as=style>
<link href=/css/chunk-vendors.7724753e.css rel=preload as=style>
<link href=/js/app.9a3ab992.js rel=preload as=script>
<link href=/js/chunk-vendors.6808fe3a.js rel=preload as=script>
<link href=/css/chunk-vendors.7724753e.css rel=stylesheet>
<link href=/css/app.52c62e82.css rel=stylesheet>
</head>
<body>
<noscript>
<strong>We're sorry but TestApp doesn't work properly without JavaScript enabled. Please enable it to continue.</strong>
</noscript>
<div id=app></div>
<script src=/js/chunk-vendors.6808fe3a.js></script>
<script src=/js/app.9a3ab992.js></script>
</body>
</html>

编辑:

我还尝试在这里使用 gorilla/mux 示例:
https://blog.questionable.services/article/vue-react-ember-server-golang/

这是我的“dist”的文件夹结构。

enter image description here

最佳答案

在浏览器上按 F12 并转到控制台选项卡以查看错误

关于vue.js - Vue 应用程序在通过 npm 的 serve 函数提供服务时工作,但在通过 golang net/http 包提供服务时出现空白页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61744753/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com