在VScode和Chrome中调试Vue,未绑定断点

Bwa*_*wal 5 debugging breakpoints vue.js visual-studio-code

我正在尝试调试我在 VSCode 和 Chrome 中编写的 Vue 网站。当我在data() { return {...} }函数中放置断点时,它会停止,但是如果我尝试将它放置在 Vue 文件或 JS 服务中的方法中,一旦我通过调试配置启动 Chrome,断点就会解除绑定。有没有人对如何保持断点有任何想法?这是我的配置文件:

"version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Chrome",
            "request": "launch",
            "type": "pwa-chrome",
            "url": "http://localhost:8080",
            "webRoot": "${workspaceFolder}/client/meet-for-lunch/src",
            "sourceMapPathOverrides": {
              "webpack:///src/*": "${webRoot}/*"
            }
        },
        {
            "type": "node",
            "request": "launch",
            "name": "Debug server",
            "runtimeExecutable": "nodemon",
            "program": "${workspaceFolder}/server/bin/www",
            "restart": true,
            "console": "integratedTerminal",
            "internalConsoleOptions": "neverOpen",
            "skipFiles": [
                "<node_internals>/**"
            ]
        }

    ]
}
Run Code Online (Sandbox Code Playgroud)

我包括服务器的调试配置,因为在工作中。

这是我尝试调试的方法示例(来自 Vue 文件),我在this.error = null. 该方法正常运行,所以我希望它在断点处停止:

        methods: {
            async login() {
                try {
                    this.error = null;
                    const response = await AuthenticationService.login({
                        email: this.email,
                        password: this.password
                    })
                    this.$store.dispatch('setToken', response.data.token)
                    this.$store.dispatch('setUser', response.data.user)

                }
                catch (err) {
                    console.log(`An error has occured: ${JSON.stringify(err.response)}`)
                    this.error = err.response.data.error
                }
            }
        } 
Run Code Online (Sandbox Code Playgroud)

我也在尝试调试我的服务:

login(credentials) {
        return Api().post('/login', credentials)
    }
Run Code Online (Sandbox Code Playgroud)

Api 对象只是创建了 Axios 请求

谢谢,

小智 18

https://www.codegrepper.com/code-examples/javascript/vuejs+vscode+unbound+breakpoint

经过一整天的搜索,这解决了我的问题

{
"version": "0.2.0",  
"configurations": [  
  {
    "name": "WSL Chrome",
    "type": "chrome",
    "request": "launch",
    "url": "http://localhost:8080",
    "webRoot": "${workspaceFolder}/src",
    "sourceMapPathOverrides": {
        "webpack:///./src/*": "${webRoot}/*",
        "webpack:///src/*": "${webRoot}/*"
    }
  }
]
Run Code Online (Sandbox Code Playgroud)

}

  • 在尝试了大约 20 个其他解决方案后,这个方法成功了。谢谢你! (2认同)
  • 这篇[文章](https://vuejs.org/v2/cookbook/debugging-in-vscode.html#Launching-the-Application-from-VS-Code)几乎向我展示了所有必需的步骤。但对我来说,窍门是你覆盖`./src/*`。 (2认同)

Jam*_* L. 3

当我在 VSCode 中有未绑定断点时,我最终需要使用--inspector--debug-brk=5858标志来启动该进程。除此之外,launch.json给我带来了很多麻烦,这些资源很有帮助

launch.json 示例:

    {
        "type": "node",
        "request": "attach",
        "name": "Node: Nodemon",
        "processId": "${command:PickProcess}",
        "restart": true,
        "protocol": "inspector",
    },
    {
        "name": "Launch tests via NPM",
        "type": "node",
        "request": "launch",
        "cwd": "${workspaceRoot}",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
            "run-script", "testDebug"
        ],
        "port": 5858
    }
Run Code Online (Sandbox Code Playgroud)

包.json

"scripts": {
  "start": "NODE_PATH=./src DEBUG=express:* NODE_ENV=dev nodemon -w src --ext ts --exec node --inspect -r tsconfig-paths/register -r ts-node/register src/index.ts",
  "testDebug": "NODE_ENV=test ts-mocha --debug-brk=5858 --paths -p tsconfig.json",
 }
Run Code Online (Sandbox Code Playgroud)