Home > Web Front-end > JS Tutorial > body text

How to implement automatic formatting using Eslint in Vue-cli

亚连
Release: 2018-06-05 09:48:32
Original
3064 people have browsed it

This article mainly introduces the method of Vue-cli Eslint automatically formatting the code in vscode. Now I share it with you and give it as a reference.

Another very important function of the editor is code formatting. VS Code provides formatting of common files by default, such as .js, .html, etc.

Add formatting support for .vue files

Here we add formatting support for .vue files.

1. Install the Vetur plug-in
2. Add the following rules in the settings of VS Code:

{
   "vetur.format.defaultFormatter": {
    "html": "prettier",
    "css": "prettier",
    "postcss": "prettier",
    "scss": "prettier",
    "less": "prettier",
    "js": "prettier",
    "ts": "prettier",
    "stylus": "stylus-supremacy"
  }
}
Copy after login

Here is Set the formatting plug-in prettier used by Vetur by default. In this way, formatting support is provided for html and javascript codes in .vue files.

vue eslint code automatic formatting

  1. vue-cli code style is JavaScript Standard Style code inspection specifications are strict, if you are not careful It cannot run. Use eslint's autoFixOnSave to automatically format the code when saving it

  2. VSCode expansion plug-in recommendation (applicable to HTML, Node, Vue, and React development)

Recommended reading:

  1. vscode plug-in recommendation

  2. JavaScript Standard Style code style specification

Text eslint automatic formatting

Configuration environment:

npm i -g eslint-plugin-vue
#or
npm i -S eslint-plugin-vue
Copy after login

Create the file under the project and path: .eslintrc | .eslint.js

// 添加插件
"plugins": [
  "vue"
]
Copy after login

Add in your vscode settings file:

1. Add the eslint plug-in to vscode
2. Add the vetur plug-in to vscode
3. Modify your setting.json

// 添加进你的vscode的 setting.json

"eslint.autoFixOnSave": true,
"eslint.validate": [
  "javascript",{
    "language": "vue",
    "autoFix": true
  },"html",
  "vue"
],
Copy after login

The above is what I compiled for everyone. I hope it will be helpful to everyone in the future.

Related articles:

Use webpack template in vue-cli to solve project construction and packaging path problems

In vue Zhongbus Global Event Center (detailed tutorial)

##Detailed interpretation of change detection issues in the Angular series

The above is the detailed content of How to implement automatic formatting using Eslint in Vue-cli. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!