vscode[vue开发]插件推荐

前提
使用vscode作为vue项目开发工具,同时使用vue脚手架搭建项目。

vscode下载地址

https://code.visualstudio.com/

vscode插件推荐

1.EsLint 和 Prettier ESLint 这两个插件配合使用,用于对项目代码进行eslint检查和根据eslint规则进行格式化操作。快捷键:shift + alt + f
通常情况下项目必须要有eslint插件以及eslint的配置文件;如:
在这里插入图片描述

2.Vetur —— vue代码高亮,代码提示,代码格式化等,格式化方面与 Prettier ESLint有区别,可以在vscode上自由选择方式

3.Auto Close Tag —— 自动闭合HTML/XML标签

4.Auto Rename Tag —— 自动完成另一侧标签的同步修改

5.Path Intellisense —— 自动路劲补全

6.HTML CSS Support —— 让 html 标签上写class 智能提示当前项目所支持的样式

7.Vue 3 Snippets —— vue2 和 vue3代码快速生成插件。如:vFor ===> v-for="" :key=""

8.JavaScript(ES6) code snippets —— ES6语法智能提示以及快速输入,除js外还支持.ts,.jsx,.tsx,.html,.vue,省去了配置其支持各种包含js代码文件的时间
打开随便一个vue文件

9.Bracket Pair Colorizer —— 给括号加上不同的颜色,便于区分不同的区块

10.Chinese (Simplified) Language Pack for Visual Studio Code —— 中文翻译包

11.vscode-icons —— 图标补充插件

个人vscode配置:

{
  // 主题
  "workbench.colorTheme": "Default Light+",
  "window.zoomLevel": 1,
  // 配置使能每一种语言默认格式化规则
  "[vue]": {
    "editor.defaultFormatter": "rvest.vs-code-prettier-eslint"
  },
  "[javascript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },
  "[html]": {
    "editor.defaultFormatter": "vscode.html-language-features"
  },
  "[json]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  // js代码编辑区域
  "javascript.validate.enable": false,
  //让函数(名)和后面的括号之间加个空格
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true, 
  // editor 编辑区域
  // 重新设定tabsize
  "editor.tabSize": 2,
  // vscode默认启用了根据文件类型自动设置tabsize的选项
  "editor.detectIndentation": false,
  "editor.quickSuggestions": {
    //开启自动显示建议
    "other": true,
    "comments": true,
    "strings": true
  },
   //保存时自动将代码按ESLint格式进行格式化
  "editor.formatOnSave": true,
  // 每次保存的时候将代码按eslint格式进行修复,vscode es6语法检测配置
  "editor.codeActionsOnSave": {
    "source.fixAll.eslint": true
  },
  // auto-close-tag 编辑区域
  "auto-close-tag.activationOnLanguage": [
    "xml",
    "php",
    "blade",
    "ejs",
    "jinja",
    "javascript",
    "javascriptreact",
    "typescript",
    "typescriptreact",
    "plaintext",
    "markdown",
    "vue",
    "liquid",
    "erb",
    "lang-cfml",
    "cfml",
    "HTML (EEx)",
    "HTML (Eex)",
    "plist"
  ],
  // eslint编辑区域
  "eslint.codeActionsOnSave.mode": "problems",
  "eslint.codeAction.showDocumentation": {
    "enable": true
  },
  // files编辑区域
  "files.associations": {
    "*.vue": "vue"
  },
  // vetur的常规配置项
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.js": "none",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-expand-multiline"
    },
    "prettyhtml": {
      "printWidth": 200,
      "singleQuote": false,
      "wrapAttributes": false,
      "sortAttributes": true
    },
    "prettier": {
      "semi": false,
      "singleQuote": true
    },
  },
  "vetur.grammar.customBlocks": {
    "docs": "md",
    "i18n": "json"
  },
  // vetur emmet的配置
  "emmet.excludeLanguages": [
    "markdown"
  ],
}

个人eslint 配置

.eslintrc.js文件内容


module.exports = {
  root: true,
  parserOptions: {
    parser: 'babel-eslint',
    sourceType: 'module'
  },
  env: {
    browser: true,
    node: true,
    es6: true,
  },
  extends: ['plugin:vue/recommended', 'eslint:recommended'],

  // add your custom rules here
  //it is base on https://github.com/vuejs/eslint-config-vue
  // 0 允许 1 警告 2 禁止
  rules: {
    "vue/max-attributes-per-line": [2, {
      "singleline": 10,
      "multiline": {
        "max": 1,
        "allowFirstLine": false
      }
    }],
    'vue/html-closing-bracket-newline': 'off',
    "vue/singleline-html-element-content-newline": "off",
    "vue/multiline-html-element-content-newline": "off",
    "vue/name-property-casing": ["error", "PascalCase"],
    "vue/no-v-html": "off",
    'accessor-pairs': 2, // 在对象中使用getter/setter
    'arrow-spacing': [2, { //=>的前/后括号
      'before': true,
      'after': true
    }],
    'block-spacing': [2, 'always'],
    'brace-style': [2, '1tbs', { //大括号风格
      'allowSingleLine': true
    }],
    'camelcase': [1, { //是否强制驼峰法命名
      'properties': 'always'
    }],
    'comma-dangle': [2, 'never'],// 对象字面量项尾不能有逗号
    'comma-spacing': [2, { //逗号前后的空格
      'before': false,
      'after': true
    }],
    'comma-style': [2, 'last'],//逗号风格,换行时在行首还是行尾
    'constructor-super': 2,//非派生类不能调用super,派生类必须调用super
    'curly': [2, 'multi-line'],// 必须使用 if(){} 中的{}
    'dot-location': [2, 'property'],// 对象访问符的位置,换行的时候在行首还是行尾
    'eol-last': 2, // 文件以单一的换行符结束
    'eqeqeq': ["error", "always", { "null": "ignore" }],// 必须使用全等除了中括号内容
    'generator-star-spacing': [2, { //生成器函数*的前后空格
      'before': true,
      'after': true
    }],
    'handle-callback-err': [2, '^(err|error)$'], //nodejs 处理错误
    'indent': [2, 2, { //缩进风格
      'SwitchCase': 1
    }],
    'jsx-quotes': [2, 'prefer-single'], // 引号类型,单引号
    'key-spacing': [2, { // 对象字面量中冒号的前后空格
      'beforeColon': false,
      'afterColon': true
    }],
    'keyword-spacing': [2, {
      'before': true,
      'after': true
    }],
    'new-cap': [2, {//函数名首行大写必须使用new方式调用,首行小写必须用不带new方式调用
      'newIsCap': true,
      'capIsNew': false
    }],
    'new-parens': 2,//new时必须加小括号
    'no-array-constructor': 2,//禁止使用数组构造器
    'no-caller': 2,//禁止使用arguments.caller或arguments.callee
    'no-console': 'off', // console 不限制
    'no-class-assign': 2,//禁止给类赋值
    'no-cond-assign': 2, // 禁止在条件表达式中使用赋值语句
    'no-const-assign': 2,//禁止修改const声明的变量
    'no-control-regex': 0,//禁止在正则表达式中使用控制字符
    'no-delete-var': 2,//不能对var声明的变量使用delete操作符
    'no-dupe-args': 2,// 函数参数不能重复
    'no-dupe-class-members': 2,
    'no-dupe-keys': 2,// 在创建对象字面量时不允许键重复 {a:1,a:1}
    'no-duplicate-case': 2,// switch中的case标签不能重复
    'no-empty-character-class': 2, // 正则表达式中的[]内容不能为空
    'no-empty-pattern': 2,
    'no-eval': 2,//禁止使用eval
    'no-ex-assign': 2,//禁止给catch语句中的异常参数赋值
    'no-extend-native': 2, // 禁止扩展native对象
    'no-extra-bind': 2,//禁止不必要的函数绑定
    'no-extra-boolean-cast': 2,// 不必要的bool转换
    'no-extra-parens': [2, 'functions'],// 非必要的括号
    'no-fallthrough': 2,//禁止switch穿透
    'no-floating-decimal': 2,// 禁止省略浮点数中的0 .5 3.
    'no-func-assign': 2,// 禁止重复的函数声明
    'no-implied-eval': 2,//禁止使用隐式eval
    'no-inner-declarations': [2, 'functions'],//禁止在块语句中使用声明(变量或函数)
    'no-invalid-regexp': 2, // 禁止无效的正则表达式
    'no-irregular-whitespace': 2,//不能有不规则的空格
    'no-iterator': 2,//禁止使用__iterator__ 属性
    'no-label-var': 2,//label名不能与var声明的变量名相同
    'no-labels': [2, {// 禁止标签声明
      'allowLoop': false,
      'allowSwitch': false
    }],
    'no-lone-blocks': 2, // 禁止不必要的嵌套块
    'no-mixed-spaces-and-tabs': 2, //关闭禁止混用tab和空格
    'no-multi-spaces': 2, // 不能用多余的空格
    'no-multi-str': 2,//字符串不能用\换行
    'no-multiple-empty-lines': [2, {//空行最多不能超过2行
      'max': 1
    }],
    'no-native-reassign': 2, // 不能重写native对象
    'no-negated-in-lhs': 2,//in 操作符的左边不能有!
    'no-new-object': 2,//禁止使用new Object()
    'no-new-require': 2,//禁止使用new require
    'no-new-symbol': 2,//禁止使用new symbol
    'no-new-wrappers': 2,//禁止使用new创建包装实例,new String new Boolean new Number
    'no-obj-calls': 2,//不能调用内置的全局对象,比如Math() JSON()
    'no-octal': 2,//禁止使用八进制数字
    'no-octal-escape': 2,//禁止使用八进制转义序列
    'no-path-concat': 2,//node中不能使用__dirname或__filename做路径拼接
    'no-proto': 2,//禁止使用__proto__属性
    'no-redeclare': 2,// 禁止重复声明变量
    'no-regex-spaces': 2,//禁止在正则表达式字面量中使用多个空格 /foo bar/
    'no-return-assign': [2, 'except-parens'],// return 语句中不能有赋值表达式
    'no-self-assign': 2,
    'no-self-compare': 2,// 不能比较自身
    'no-sequences': 2,// 禁止使用逗号运算符
    'no-shadow-restricted-names': 2,// 严格模式中规定的限制标识符不能作为声明时的变量名使用
    'no-spaced-func': 2,//函数调用时 函数名与()之间不能有空格
    'no-sparse-arrays': 2,// 禁止稀疏数组, [1,,2]
    'no-this-before-super': 2,//在调用super()之前不能使用this或super
    'no-throw-literal': 2,// 禁止抛出字面量错误 throw "error";
    'no-trailing-spaces': 2,//一行结束后面不要有空格
    'no-undef': 2,
    'no-undef-init': 2,//变量初始化时不能直接给它赋值为undefined
    'no-unexpected-multiline': 2, // 避免多行表达式
    'no-unmodified-loop-condition': 2,
    'no-unneeded-ternary': [2, {//禁止不必要的嵌套
      'defaultAssignment': false
    }],
    'no-unreachable': 2, // 不能有无法执行的代码
    'no-unsafe-finally': 2,
    'no-unused-vars': [2, { // 不能有声明后未被使用的变量或参数
      'vars': 'all',
      'args': 'none'
    }],
    'no-useless-call': 2,// 禁止不必要的call和apply
    'no-useless-computed-key': 2,
    'no-useless-constructor': 2,
    'no-useless-escape': 0,
    'no-whitespace-before-property': 2,
    'no-with': 2, // 禁用with
    'one-var': [2, { // 连续声明
      'initialized': 'never'
    }],
    'operator-linebreak': [2, 'after', { //换行时运算符在行尾还是行首
      'overrides': {
        '?': 'before',
        ':': 'before'
      }
    }],
    'padded-blocks': [2, 'never'],//块语句内行首行尾是否要空行
    'quotes': [2, 'single', { // 引号类型
      'avoidEscape': true,
      'allowTemplateLiterals': true
    }],
    'semi': [2, 'never'],//语句强制分号结尾
    'semi-spacing': [2, { //分号前后空格
      'before': false,
      'after': true
    }],
    'space-before-blocks': [2, 'always'],//不以新行开始的块{前面要不要有空格
    'space-before-function-paren': 'off',// 函数定义时括号前面要不要有空格
    'space-in-parens': [2, 'never'],//小括号里面要不要有空格
    'space-infix-ops': 2,// 中缀操作符周围要不要有空格
    'space-unary-ops': [2, { //一元运算符的前/后要不要加空格
      'words': true,
      'nonwords': false
    }],
    'spaced-comment': [2, 'always', { //注释风格要不要有空格什么的
      'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
    }],
    'template-curly-spacing': [2, 'never'],
    'use-isnan': 2,//禁止比较时使用NaN,只能用isNaN()
    'valid-typeof': 2, // 必须使用合法的typeof的值
    'wrap-iife': [2, 'any'],//立即执行函数表达式的小括号风格
    'yield-star-spacing': [2, 'both'],
    'yoda': [2, 'never'],//禁止尤达条件
    'prefer-const': 2, //首选const
    'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // 生产环境禁止,开发环境可以使用debugger
    'object-curly-spacing': [2, 'always', {//大括号内是否允许不必要的空格
      objectsInObjects: false
    }],
    'array-bracket-spacing': [2, 'never']//是否允许非空数组里面有多余的空格
  }
}


.eslintignore 文件内容

build/*.js
src/assets
public
dist

.prettierrc 文件内容

{
"tabWidth": 2,

"useTabs": false,

"singleQuote": true,

"semi": false

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值