一直以来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"
},
"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>