gpt4 book ai didi

visual-studio-code - JS 文件未在 VS Code 中加载到 Live Server 上

转载 作者:行者123 更新时间:2023-12-04 17:47:49 24 4
gpt4 key购买 nike

我开始使用 VS Code,所以我没有很多经验。看起来我需要手动添加我需要的一切。来自 Visual Studio,虽然我看到了好处,但一开始有点奇怪。

我选择 Live Server ( https://marketplace.visualstudio.com/items?itemName=ritwickdey.LiveServer ) 作为我将在 Visual Studio Code 中处理的项目的 Web 服务器。不确定这是否是一个不错的选择,但评价很高。

这是我遇到的问题:当我启动 Live Server 时,我可以拉起我的 html文件在根目录,但 Live Server 拒绝加载 bundle.js文件也位于根文件夹中。

它不加载 bundle.js文件通过 index.html引用此页面的页面 js文件。如果我只是输入 bundle.js 的 URL,它也会拒绝加载它。在浏览器中,即 http://127.0.0.1:5500/bundle.js .当我尝试访问 bundle.js 时文件通过浏览器,我得到:

Cannot GET /bundle.js



当我在 Chrome 中启动开发人员工具时,我看到以下内容,但是当我转到实际文件夹时,我看到该文件在那里。
enter image description here

知道为什么会发生这种情况以及如何解决吗?

最佳答案

这个问题可能很老,但我在从 XAMPP 切换到 Live Server 扩展时遇到了同样的问题。脚本标签在 XAMPP 中加载良好,但在 Live Server 上显示为 404。问题原来是相对路径格式。
我有:

src="/main.js"
它必须是:
src="./main.js"
带点。

关于visual-studio-code - JS 文件未在 VS Code 中加载到 Live Server 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47603946/

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