VScode 自动修复vue项目中eslint报错

1、安装插件 eslint-plugin-vue

npm i -g eslint-plugin-vue

2、修改项目跟路径下的文件:.eslint.js
添加vue选项

VScode 自动修复vue项目中eslint报错_第1张图片
3、添加eslint 和 vetur 插件,直接在插件库中下载


4、修改vscode首选项配置
【汉化版 文件>首选项>设置找到对应的配置文件】
【英文版 file>preferences>setting找到对应的配置文件】

【找到配置文件添加如下代码】

"eslint.autoFixOnSave": true,
"eslint.validate": [
    "javascript",{
        "language": "vue",
        "autoFix": true
    },"html",
    "vue"
],

如图所示

VScode 自动修复vue项目中eslint报错_第2张图片

VScode 自动修复vue项目中eslint报错_第3张图片

附上settings.json代码

{
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "eslint.validate": [
    "javascript",
    "javascriptreact",
    {
      "language": "html",
      "autoFix": true
    },
    {
      "language": "vue",
      "autoFix": true
    }, "html",
    "vue"
  ],
  // 保存自动修复
  "eslint.autoFixOnSave": true,
  // jsx自动修复有问题,取消js的format
  "editor.formatOnSave": true,
  // Enable/disable default JavaScript formatter (For Prettier)
  "javascript.format.enable": true,
  "prettier.singleQuote": true,
  // 点击保存时,根据 eslint 规则自定修复,同时集成 prettier 到 eslint 中
  "prettier.eslintIntegration": true,
}


配置完成,重启vscode,在保存时就会自动修复eslint的报错。
 

你可能感兴趣的:(实习前端框架)