vscode 在vue项目中引用eslint、并格式化

567 阅读1分钟
  1. 在 vscode 中安装 eslint、prittier、vetur 插件
  2. 在 vue 项目安装 eslint-plugin-vue 包
  3. 在项目根目录中使用命令行执行 eslint --init 可以进行一些初始化(前提条件全局安装eslint),并在根目录形成一个eslintrc.js文件(下面贴出我配置的eslintrc.js)
module.exports = {
  "env": {
    "browser": true,
    "es6": true,
    node: true
  },
  "extends": [
    "eslint:recommended",
    "plugin:vue/essential"
  ],
  "globals": {
    "Atomics": "readonly",
    "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
    "ecmaVersion": 2018,
    "sourceType": "module"
  },
  "plugins": [
    "vue"
  ],
  "rules": {
    'no-console': 'off',
    'no-debugger': 'off',
    'camelcase': 1,
    'quotes': ['error', 'single', {
      avoidEscape: true, // 允许字符串使用单引号或双引号,只要字符串中包含了一个其它引号,否则需要转义
      allowTemplateLiterals: true // 允许字符串使用反勾号
    }],
  }
};

  1. 然后是vscode里面的配置
{
  "workbench.colorTheme": "Dracula Soft",
  "[html]": {
    "editor.defaultFormatter": "vscode.html-language-features"
  },
  "[javascript]": {
    "editor.defaultFormatter": "HookyQR.beautify"
  },
  "editor.tabSize": 2,
  "[less]": {
    "editor.defaultFormatter": "HookyQR.beautify"
  },
  "editor.formatOnSave": false,
  "editor.formatOnType": false,
  "window.zoomLevel": 0,
  "explorer.confirmDragAndDrop": false,
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
  "git.ignoreMissingGitWarning": true,
  "git.path": "D:/git/Git/mingw64/bin/git.exe",
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true, // 根据eslint进行修复
    "enable": true
  },
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true, // 在函数的括号前面插入空格
}