1.使用Beautify插件配置 自动格式化按如下步骤设置
- 在工作目录下建立.jsbeautifyrc文件.
1
2
3
4
5
6
7
8
9
10{
"brace_style": "none,preserve-inline",
"indent_size": 2,
"indent_char": " ",
"jslint_happy": true,
"unformatted": [""],
"css": {
"indent_size": 2
}
}
注释
- brace_style,格式风格,详见官方说明(为避免和eslint默认检查冲突,建议此属性设置为 none,preserve-inline)
- indent_size,缩进长度(为避免和eslint默认检查冲突,建议此属性设置为 2)
- indent_char,缩进填充的内容(充满♂)
- jslint_happy:true,若你要搭配jslint使用,请开启此选项
- unformatted:[“a”,”pre”],这里放不需要格式化的标签类型。注意 template 也是默认不格式化的,.vue 的template 标签如果需要格式化请在 .jsbeautifyrc 重新定义不带 template 的声明属性
2.启用保存时自动
在VSCode的配置文件里添加 editor.formatOnSave:true 即可实现保存时自动格式化
3.快捷键
在 VS Code 的键盘快捷方式文件里添加1
2
3
4
5{
"key": "cmd+b", // 自己定键位
"command": "HookyQR.beautify",
"when": "editorFocus"
}
4.单独配置vue
- 文件-> 设置 -> settings.json 中添加属性
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21"beautify.language": {
"js": {
"type": [
"javascript",
"json"
],
"filename": [
".jshintrc",
".jsbeautify"
]
},
"css": [
"css",
"scss"
],
"html": [
"htm",
"html",
"vue" //< 这条给vue配置
]
}
插件备份(自己研究)
1 | { |