vscode使用Ctrl+s保存代码自动格式化html/css/js

1、使用时首先安装一下插件:

1、ESlint //代码分格检查,
2、vetur // 语法高亮,Vetur支持.vue文件的语法高亮显示,除了支持template模板以外,还支持大多数主流的前端开发脚本和插件
3、Prettier - Code formatter
4、Manta's Stylus Supremacy // 格式化 css

2、修改配置:

vscode使用Ctrl+s保存代码自动格式化html/css/js_第1张图片

3、设置配置内容:

{
  // 是否允许自定义的snippet片段提示
  "editor.snippetSuggestions": "top",
  "editor.fontSize": 22,
  "editor.fontWeight": "400",
  "editor.formatOnType": true,
  "guides.enabled": false,
  "editor.tabSize": 2,
  // 配置文件关联,以便启用对应的提示
  "files.associations": {
    "*.vue": "vue",
    "*.wxss": "css"
  },
  // 配置emmet是否启用tab展开缩写
  "emmet.triggerExpansionOnTab": true,
  // 配置emmet对文件类型的支持
  "emmet.syntaxProfiles": {
    "javascript": "jsx",
    "vue": "html",
    "vue-html": "html"
  },
  // 是否开启eslint检测
  "eslint.enable": true,
  // 文件保存时是否根据eslint进行格式化
  "eslint.autoFixOnSave": true,
  // eslint配置文件
  "eslint.options": {
    "extensions": [
      ".js",
      ".vue"
    ]
  },
  // eslint能够识别的文件后缀类型
  "eslint.validate": [
    "javascript",
    {
      "language": "vue",
      "autoFix": true
    },
    "html",
    "vue"
  ],
  "search.exclude": {
    "**/node_modules": true,
    "**/bower_components": true,
    "**/dist": true
  },
  // 格式化快捷键(默认):Shift+Alt+F
  // #每次保存的时候将代码按eslint格式进行修复 
  "prettier.eslintIntegration": true,
  "terminal.integrated.rendererType": "dom",
  "diffEditor.renderSideBySide": false,
  // vscode默认启用了根据文件类型自动设置tabsize的选项
  "editor.detectIndentation": false,
  // #每次保存的时候自动格式化 
  "editor.formatOnSave": true,
  //  #去掉代码结尾的分号 
  "prettier.semi": false,
  //  #使用单引号替代双引号 
  "prettier.singleQuote": true,
  //  #让函数(名)和后面的括号之间加个空格
  "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
  // #这个按用户自身习惯选择 
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  // #让vue中的js按编辑器自带的ts格式进行格式化 
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      "wrap_attributes": "force-aligned"
      // #vue组件中html代码格式化样式
    }
  },
  // 格式化stylus, 需安装Manta's Stylus Supremacy插件
  "stylusSupremacy.insertColons": false, // 是否插入冒号
  "stylusSupremacy.insertSemicolons": false, // 是否插入分好
  "stylusSupremacy.insertBraces": false, // 是否插入大括号
  "stylusSupremacy.insertNewLineAroundImports": false, // import之后是否换行
  "stylusSupremacy.insertNewLineAroundBlocks": false // 两个选择器中是否换行
}

 

你可能感兴趣的:(三,VUE学习)