【问题标题】:Javascript works on localhost, but it stops on deploy github pages or vercelJavascript 在本地主机上工作,但在部署 github 页面或 vercel 时停止
【发布时间】:2021-07-19 14:27:56
【问题描述】:

谁能告诉我为什么 javascript 可以在 localhost 上运行,但是当使用 github Pages 或 vercel 时,javascript 会停止?

github上的代码:https://github.com/Marincor/Bx-Bank

部署github页面:https://marincor.github.io/Bx-Bank/

在 Vercel 上部署:https://bx-bank.vercel.app/

当我转到页面 index.html 和 cadastro.html 的开发工具源时,它们没有我链接的 JS 文件夹。

print of devTools chrome sourcers tab

print of github JS folder

print of the script src inside the html file

我不知道该怎么办,有什么建议吗?

由于某种原因,home.html 可以使用 javascript 文件,而 index.html 和 cadastro.html 不能。

【问题讨论】:

  • 请不要要求我们调试您的 github 存储库。而是编辑问题并向其添加minimal reproducible example
  • 可能是因为在 GitHub 上它是区分大小写的。
  • 我在问题中添加了一些案例的打印件,有帮助吗?
  • 丝网印刷不是minimal reproducible example。我们无法运行它,也无法从中复制/粘贴。

标签: javascript deployment web-deployment github-pages vercel


【解决方案1】:

使用前面的 ./ 格式化脚本文件的路径,就像使用 css 链接一样:

<script type="module" src="./Assets/JS/Index.js"></script>

编辑:并注意大小写:

<script type="module" src="./Assets/JS/index.js"></script>

【讨论】:

  • 我改变了,但还没有 javascript
  • 哦,你的文件是index.js 小写,没有大写。
  • 已更改,但尚未更改。就在 javascript 工作的 home.html 上:/。在本地主机上所有文件都可以工作,我不明白
  • 现在为我工作。在浏览器中打开您的开发工具后,确保在网络选项卡中选择禁用缓存并刷新页面。或者,如果这没有意义,请按住 Ctrl,然后按键盘上的 F5。
  • 羊毛,工作,谢谢男人
猜你喜欢
  • 1970-01-01
  • 2022-07-28
  • 2021-04-04
  • 1970-01-01
  • 1970-01-01
  • 2021-02-18
  • 1970-01-01
  • 1970-01-01
  • 2021-05-17
相关资源
最近更新 更多