vue项目开发规范配置

eslint

配置编译时是否启用

vue.config.js配置文件中增加:

module.exports = {
    lintOnSave: true,
    devServer: {
        overlay: {
            warnings: true,
            errors: true
        }
    }
}

参考文章

Configuration Files

This can be in the form of an .eslintrc.* file or an eslintConfig field in a package.json file.

There are several pieces of information that can be configured:

  • Environments - which environments your script is designed to run in. Each environment brings with it a certain set of predefined global variables.
  • Globals - the additional global variables your script accesses during execution.
  • Rules - which rules are enabled and at what error level.

配置:

    'space-before-function-paren': ['error', 'never']

prettier和eslint配合使用

参考文章

整理配置

参考文章
梳理前端开发使用eslint和prettier来检查和格式化代码问题

vscode中安装eslint插件

增加配置到settings.json中:

    "eslint.autoFixOnSave": true,  //保存时使用自动格式化
    "eslint.validate": [   //验证文件类型
        "javascript",
        "javascriptreact",
        "jsx",
        {
            "language": "vue",
            "autoFix": true
        },
        "vue",
        "html",
    ]

"vue"配置需要放到autoFix之后,否则出现在vscode中保存不能自动fix的情况。

vscode中安装vetur插件

增加配置到settings.json中:

   "vetur.format.defaultFormatterOptions": {
        "js-beautify-html": {
            "wrap_attributes": "force-aligned" //属性强制折行对齐
        },
        "prettier": {
            "singleQuote": true,
            "semi": false
        }
    }

转载于:https://www.cnblogs.com/liuchengcc/p/10464441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值