Vue Vue-cli Eslint automatically formats code in vscode
vue eslint code automatic formatting
The code style of vue-cli is JavaScript Standard Style . The code inspection specification is strict, and it cannot be run if you are not careful. Using eslint's autoFixOnSave can automatically format the code when saving the code.
- VSCode extension plugin recommendation (applicable to HTML, Node, Vue, React development)
Suggested reading:
Body eslint auto-formatting
Configuration Environment:
npm i -g eslint-plugin-vue
#or
npm i -S eslint-plugin-vue
Create the project and the files under the path: .eslintrc | .eslint.js
// 添加插件
"plugins": [
"vue"
]
In your vscode settings file add:
- 1. Add eslint plugin to vscode
- 2. Add vetur plugin to vscode
- 3. Modify your setting.json
// 添加进你的vscode的 setting.json
"eslint.autoFixOnSave": true,
"eslint.validate": [
"javascript",{ "language": "vue", "autoFix": true },"html", "vue" ],