您当前的位置: 首页 >  vscode

彭世瑜

暂无认证

  • 6浏览

    0关注

    2791博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

VsCode:Vue单文件格式化属性换行显示

彭世瑜 发布时间:2022-06-30 11:13:23 ,浏览量:6

需要安装插件vetur 文档:

  • vetur: https://vuejs.github.io/vetur/guide/formatting.html
  • js-beautify-html: https://github.com/vuejs/vetur/blob/master/server/src/modes/template/services/htmlFormat.ts
  • prettier https://prettier.io/docs/en/options.html

settings.json

{
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  }
  // 保存时候自动格式化
  "vetur.validation.template": false,
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatterOptions": {
    "js-beautify-html": {
      //属性换行
      "wrap_attributes": "force",
      "indent_size": 2,
      "indent_char": " "
    },

    "prettyhtml": {
      "printWidth": 100,
      "singleQuote": true,
      "wrapAttributes": false,
      "sortAttributes": true
    },
    
    // css/scss/less/js/ts
    "prettier": {
      //设置分号
      "semi": true,
      //双引号变成单引号
      "singleQuote": true,
      //尾部逗号 es5|none|all
      "trailingComma": "es5",
    }
  }  
}

js-beautify-html 选项

end_with_newline: false, // End output with newline
indent_char: ' ', // Indentation character
indent_handlebars: false, // e.g. {{#foo}}, {{/foo}}
indent_inner_html: false, // Indent  and  sections
indent_scripts: 'keep', // [keep|separate|normal]
indent_size: 2, // Indentation size
indent_with_tabs: false,
max_preserve_newlines: 1, // Maximum number of line breaks to be preserved in one chunk (0 disables)
preserve_newlines: true, // Whether existing line breaks before elements should be preserved
unformatted: [], // Tags that shouldn't be formatted. Causes mis-alignment
wrap_line_length: 0, // Lines should wrap at next opportunity after this number of characters (0 disables)
wrap_attributes: 'force-expand-multiline' as any
// Wrap attributes to new lines [auto|force|force-aligned|force-expand-multiline] ["auto"]
关注
打赏
1665367115
查看更多评论
立即登录/注册

微信扫码登录

0.0619s