vscode vue格式化不换行

博客作者分享了解决VSCode中Vue代码格式化问题的方法,通过配置settings.json文件,特别是使用vuter插件,并调整相关格式化选项,如禁用html标签自动换行,实现更理想的代码排版效果。
摘要由CSDN通过智能技术生成

一直以来VS code----vue的代码格式化都差强人意,html会自动展开,真的很难受,类似这样子

<template>
  <div id="energy">
    <div
      class="line-chart-div"
      :style="{
        width: innerWidth / 4.5 + 'px',
        height: innerHeight / 5 + 'px',
        marginLeft: innerWidth / 44 + 'px',
        marginBottom: innerHeight / 40 + 'px',
        fontSize: innerHeight / 50 + 'px',
      }"
      v-for="i in 16"
      :key="i"
    >
      <div
        class="line-chart"
        style="width: 100%; height: 100%"
        :style="{ paddingTop: innerHeight / 30 + 'px' }"
      ></div>
      <div class="title" :style="{ fontSize: parseInt(innerHeight / 60) }">
        标题
      </div>
    </div>
  </div>
</template>

于是今天决定把它改了,首先确保你安装了vuter这个插件,另外不要下载其他的格式化插件了。

打开设置搜索code actions on save:reles点击=>在settings.json中编辑,将下面这些代码全部复制过去覆盖

{
  "files.autoSave": "onFocusChange",
  "editor.suggestSelection": "recentlyUsed",
  "editor.autoClosingDelete": "always",
  "editor.autoClosingBrackets": "always",
  "editor.autoClosingOvertype": "always",
  "editor.guides.bracketPairs": true,
  "editor.guides.bracketPairsHorizontal": true,
  "editor.suggest.insertMode": "replace",
  "editor.tabCompletion": "on",
  "bracketPairColorizer.depreciation-notice": false,
  "git.ignoreMissingGitWarning": true,
  "[vue]": {
    "editor.defaultFormatter": "octref.vetur"
  },
  "editor.formatOnPaste": true,
  "editor.quickSuggestions": {
    "strings": true
},
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  // 禁止html标签自动换行
  "vetur.format.defaultFormatter.html": "js-beautify-html",
  "vetur.format.defaultFormatter.js": "vscode-typescript",
  "vetur.format.defaultFormatterOptions": {
   "js-beautify-html": {
   "wrap_attributes": "auto"
   },
  "prettyhtml": {
   "printWidth": 1000,
  "singleQuote": false,
   "wrapAttributes": false,
   "sortAttributes": false
  }
   },
  "[json]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "editor.defaultFormatter": "vscode.html-language-features",
  "[javascript]": {
    "editor.defaultFormatter": "vscode.typescript-language-features"
  },
  "go.alternateTools": {
  
  },
  "go.toolsManagement.autoUpdate": true,
  "workbench.colorTheme": "Solarized Dark",
  "git.autofetch": true,
  "[python]": {
    "editor.defaultFormatter": "ms-python.python"
  },
  "explorer.confirmDragAndDrop": false,
  "[less]": {
    "editor.defaultFormatter": "vscode.css-language-features"
  },
  "git.confirmSync": false,
  "breadcrumbs.enabled": false,
  "editor.renderWhitespace": "none",
  "editor.renderControlCharacters": false,
  "editor.minimap.enabled": false,
  "workbench.startupEditor": "none",
  "workbench.iconTheme": "vscode-icons",
  "security.workspace.trust.untrustedFiles": "open",
  "editor.codeActionsOnSave": {
  
  }
}

最终结果是这样

<template>
  <div id="energy">
    <div class="line-chart-div" :style="{width:innerWidth/4.5+'px',height:innerHeight/5+'px',marginLeft:innerWidth/44+'px',marginBottom:innerHeight/40+'px',fontSize:innerHeight/50+'px'}" v-for="i in 16" :key="i">
      <div class="line-chart" style="width:100%;height:100%;" :style="{paddingTop:innerHeight/30+'px'}"></div>
      <div class="title" :style="{fontSize:parseInt(innerHeight/60)}">标题</div>
    </div>
  </div>
</template>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

修罗_

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值