Prerequisite
You have to install Chrome and VS Code. Also make sure you have the latest version of the Debugger for Chrome extension installed in VS Code.
Before you can debug your Vue component from VS Code, you need to update the Webpack configuration to build the source map. Once this is done, our debugger has the opportunity to map the code in a compressed file back to its source file corresponding to its location. This ensures that you can debug in one application, even if your resources have been webpack optimized.
Open config/index.js
and locate devtool
the property. Update it to:
' Source-map ',
If you use vue-cli3 you need vue.config.js
to set devtool
the properties inside:
Module.exports = { configurewebpack: { 'source-map' }}
Go to the Debugger view, add a chrome configuration, and replace the content with the following
{ "version":"0.2.0", "configurations": [ { "type":"Chrome", "Request":"Launch", "name":"Vuejs:chrome", "URL":"http://localhost:8080", "WebRoot":"${workspacefolder}/src", "Breakonload":true, "Sourcemappathoverrides": { "webpack:///src/*":"${webroot}/*" } } ]}
Set breakpoints
Here response return data
Start Debugging
Use the following command on the terminal to open the application
NPM start
Go to Debug view, select ' vuejs:chrome ' configuration, then press F5 or click on the Green Play button
With a new Chrome instance open http://localhost:8080
, your breakpoint should now be hit.
For more information, please refer to the official documentation: Https://cn.vuejs.org/v2/cookbook/debugging-in-vscode.html
Vscode Debug Vue Project