需要插件: eslint,prettier - code formatter,vetur
打开用户设置文件:
// vscode默认启用了根据文件类型自动设置tabsize的选项 "editor.detectindentation": false, // 重新设定tabsize "editor.tabsize": 2, // #每次保存的时候自动格式化 "editor.formatonsave": true, // #让函数(名)和后面的括号之间加个空格 "javascript.format.insertspacebeforefunctionparenthesis": true, // #让prettier使用eslint的代码格式进行校验 "prettier.eslintintegration": true, // #去掉代码结尾的分号 "prettier.semi": false, // #使用带引号替代双引号 "prettier.singlequote": true, // #每次保存的时候将代码按eslint格式进行修复 "eslint.autofixonsave": true, // 添加 vue 支持 "eslint.validate": [ "javascript", "javascriptreact", { "language": "vue", "autofix": true } ], // #这个按用户自身习惯选择 "vetur.format.defaultformatter.html": "js-beautify-html", "vetur.format.defaultformatter.less": "prettier", "vetur.completion.autoimport": true, "vetur.format.defaultformatter.js": "vscode-typescript", "vetur.format.defaultformatteroptions": { "js-beautify-html": { "wrap_attributes": "force-aligned" } },
保存代码自动按照eslint格式化。
断点调试 (需安装debugger for chrome)
1、在浏览器中展示源码 如果你使用的是 vue cli 2,请设置并更新 config/index.js 内的 devtool 属性:
devtool: 'source-map',
如果你使用的是 vue cli 3,请设置并更新 vue.config.js 内的 devtool 属性:
module.exports = { configurewebpack: { devtool: 'source-map' }}
2、vscode中 点击在 activity bar 里的 debugger 图标来到 debug 视图,然后点击那个齿轮图标来配置一个 launch.json 的文件,选择 chrome/firefox: launch 环境。然后将生成的 launch.json 的内容替换成为相应的配置:
{ "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}/*" } }, { "type": "firefox", "request": "launch", "name": "vuejs: firefox", "url": "http://localhost:8080", "webroot": "${workspacefolder}/src", "pathmappings": [{ "url": "webpack:///src/", "path": "${webroot}/" }] } ]}
推荐教程:vscode教程
以上就是vscode怎么支持vue的详细内容。