VScode配置ESlint+Prettier - Code formatter
vue脚手架使用ctrl+s保存会提示各种报错 为了解决这种报错需要安装【ESlint】+【Prettier - Code formatter】插件
配置ESlint
添加以下配置
{
// 设置默认的代码格式化工具为 Prettier
"editor.defaultFormatter": "esbenp.prettier-vscode",
// 保存文件时自动格式化
"editor.formatOnSave": true,
// 在保存文件时自动修复所有可修复的 ESLint 错误
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
},
// 针对 Vue 文件启用特定的格式化设置
"[vue]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
// 禁用某些文件类型的格式化(例如 markdown)
"[markdown]": {
"editor.formatOnSave": false
},
// Prettier 的配置选项
"prettier.singleQuote": false,
"prettier.semi": true,
"prettier.trailingComma": "es5",
"prettier.endOfLine": "auto",
// 配置 ESLint 插件
"eslint.validate": [
"javascript",
"javascriptreact",
"vue",
"typescript",
"typescriptreact"
],
"eslint.codeActionsOnSave.rules": null
}
之后保存 退出VScode软件重新进入即可解决在书写vue中保存格式错误的情况