vscode可以运行多种代码,需要安装插件code runner
,然后点击右上角三角运行即可:
vscode也可以直接调试js代码,如下:
但通常我们需要同时调试HTML和js,此时我们使用chorme调试html,其自带的调试js,方法如下:
- VSCode 上装插件:Debugger for Chrome
- 修改launch.json
{ // Use IntelliSense to learn about possible attributes. // Hover to view descriptions of existing attributes. // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [{ "name": "谷歌浏览器", //运行html文件,用谷歌浏览器打开 "type": "chrome", "request": "launch", "url": "${file}", "sourceMaps": true, "webRoot": "${workspaceRoot}" }, { "name": "nodeLauch", //单独调试js,即可以直接运行js "type": "node", "request": "launch", "program": "${file}", //这个配置成你要调试的文件、${file}当前打开的文件 "stopOnEntry": false, "args": [], "cwd": "${workspaceRoot}", "runtimeExecutable": null, "runtimeArgs": [ "--nolazy" ], "env": { "NODE_ENV": "development" }, "console": "internalConsole", "preLaunchTask": "", "sourceMaps": false, "outDir": null } ]}
然后选择不同的调试方式进行调试: