统一前端代码风格

首先设置vscode的setting.json

{
    "window.zoomLevel": 0,
    "eslint.autoFixOnSave": true,
    "eslint.validate": [
        "javascript",
        {
            "language": "vue",
            "autoFix": true
        },
        "html",
        "vue"
    ],
    "editor.fontSize": 16,
    "editor.tabSize": 2,
    // #每次保存的时候自动格式化
    "editor.formatOnSave": true,
    "vetur.format.defaultFormatter.js": "prettier-eslint",
    "vetur.format.defaultFormatterOptions": {
        "prettier": {
            // Prettier option here
            "tabWidth": 2,
            "semi": false,
            "singleQuote": true
        }
    },
    "javascript.format.insertSpaceBeforeFunctionParenthesis": true,
    "files.autoSave": "onFocusChange",
    "vetur.format.defaultFormatter.html": "prettier",
    "[vue]": {
        "editor.defaultFormatter": "octref.vetur"
    }
}

其次安装vetur,eslint插件

统一前端代码风格_第1张图片

统一前端代码风格_第2张图片

 安装eslint-plugin-vue

yarn add eslint-plugin-vue --dev

 更改.eslinttrc.js 添加vue选项

统一前端代码风格_第3张图片

 

 

你可能感兴趣的:(JavaScript)