vue命名驼峰问题

项目场景:

vue2创建好项目的时候,在给路由组件取名字的时候,ESLint会爆出错误,需要使用驼峰命名


问题描述

比如书我们在src下创建一个Home.vue作为我们的一个路由组件

vscode提出报错:

Parsing error: No Babel config file detected for C:\Users\Admin\Desktop\back\vue-back\src\view\login.vue. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.

或者是:

Component name “index” should always be multi-word

这种类型的报错提示


解决方案:

关闭语法检查:

去vue.config.js文件添加配置

module.exports = {
  lintOnSave: false, //关闭eslint检查
}

修改eslint配置

新建.eslintrc.js,编写代码

module.exports = {
  root: true,
  env: {
    node: true,
  },
  extends: ['plugin:vue/essential', 'eslint:recommended', 'plugin:prettier/recommended'],
  parserOptions: {
    // parser: '@babel/eslint-parser',
  },
  rules: {
    // 关闭驼峰命名规则
    'vue/multi-word-component-names': ["error", {
      "ignores": ['Home']  // 添加忽略的名字
    }],
  },
}

或者将 'vue/multi-word-component-names’改成0

module.exports = {
  root: true,
  env: {
    node: true
  },
  extends: ['plugin:vue/essential', 'eslint:recommended', 'plugin:prettier/recommended'],
  parserOptions: {
    // parser: '@babel/eslint-parser',
  },
  rules: {
    // 去掉函数()前面的空格
    'space-before-function-paren': 'off',
    'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
    // 关闭驼峰命名规则
    'vue/multi-word-component-names': 0
  }
}
  • 3
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值