Vue 中的 ESLint:函数括号前缺少空格

van*_*178 1 npm eslint webpack vue.js

我使用 npm 和 vuejs/vue-cli 创建了一个项目。\n我的 package.json 文件中有 eslint 条目。

\n\n

运行代码时我收到警告:

\n\n
\n

警告 编译时有 1 个警告
\n 5:57:37 AM

\n\n

\xe2\x9c\x98 http://eslint.org/docs/rules/space-before-function-paren 函数括号前缺少\n 空格 src/components/HomePage.vue:142:9\n show() {\ ^

\n\n

\xe2\x9c\x98 1 个问题(1 个错误,0 个警告)

\n
\n\n

我应该如何处理这一行中的空间?

\n\n
export default {\n  el: \'#skills\',\n  props: {\n    skill: Object,\n    selectedId: Number\n  },\n  computed: {\n    show() { //in this line\n      return this.skill.id === this.selectedId\n    }\n  },\n...\n}\n
Run Code Online (Sandbox Code Playgroud)\n

Jer*_*itz 10

您可以在括号前添加空格或(首选选项)更新您的.eslintrc.js文件以代表您的样式偏好。

我建议您添加此规则.eslintrc.js

rules: {
  'space-before-function-paren': ['error', {
    anonymous: 'always',
    named: 'never',
    asyncArrow: 'always'
  }]
}
Run Code Online (Sandbox Code Playgroud)

文档:

https://eslint.org/docs/rules/space-before-function-paren#require-or-disallow-a-space-before-function-parenthesis-space-before-function-paren