【问题标题】:Cannot run web page in vscode无法在 vscode 中运行网页
【发布时间】:2020-06-27 14:32:25
【问题描述】:

我是 vscode 新手。

我的问题可能看起来很愚蠢。

我有 3 个文件:index.htmlindex.jsindex.css

我安装了 chrome 调试扩展,但不知道如何运行我的代码

如果我想运行/调试,我会在 chrome 中收到此错误

我确定问题出在launch.json 文件上。这里是:

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}"
        }
    ]
}

我想要的是要启动的 index.html

【问题讨论】:

  • 不,它只是静态网页
  • 使用 python SimpleHTTPServer 提供目录中的静态内容

标签: visual-studio-code


【解决方案1】:

由于您没有运行任何网络服务器以使其在 localhost 上查看,因此您不能将 url 设置为 localhost,而只需告诉 chrome 从您的工作区打开文件。

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "pwa-chrome",
            "request": "launch",
            "name": "Launch Chrome against localhost",
            "url": "${workspaceFolder}/index.html", // <-- This should be the path of the index.html file relative to the workspace
            "webRoot": "${workspaceFolder}"
        }
    ]
}

【讨论】:

    猜你喜欢
    • 2020-10-21
    • 2021-11-08
    • 1970-01-01
    • 1970-01-01
    • 2020-12-12
    • 2020-08-31
    • 2022-11-02
    • 2021-02-07
    • 1970-01-01
    相关资源
    最近更新 更多