【发布时间】:2019-01-23 13:24:38
【问题描述】:
我有一个定义组件的 .vue 文件。 对于 linter,其他 .vue 文件似乎无法正确看到它。 我收到许多 ES Lint 错误,例如:
Cannot find module '../components/LinkButton'.
我已经完成了诸如
之类的步骤在我的组件上方添加一个自定义
// @vue/componenthttps://github.com/vuejs/eslint-plugin-vue#attention确保不包含
html插件 https://github.com/vuejs/eslint-plugin-vue#why-doesnt-it-work-on-vue-file最新的 eslint 和插件
"eslint": "^5.3.0",
"eslint-plugin-vue": "^5.0.0-beta.3",
不知道还有什么可以尝试的。我的客户端 .eslintrc 如下。
module.exports = {
root: true,
env: {
browser: true,
},
"parserOptions": {
"parser": "babel-eslint",
"ecmaVersion": 2017,
"sourceType": "module"
},
// extends: 'vue',
extends: 'plugin:vue/base',
// required to lint *.vue files
plugins: [
'vue',
],
// add your custom rules here
'rules': {
'space-before-function-paren': "off",
'no-multi-spaces': 'off',
// allow paren-less arrow functions
'arrow-parens': 0,
// allow async-await
'generator-star-spacing': 0,
"no-multiple-empty-lines": 0,
"comma-dangle": 0,
"padded-blocks": 0,
// allow debugger during development
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0
}
}
```
组件定义如下
<script>
// @vue/component
const LinkButton = {
name: 'LinkButton',
props: [
'label',
'link',
'type',
'icon'
],
data () {
return {
msg: 'NLP testing'
}
}
}
module.exports = {LinkButton}
</script>
并导入
import {LinkButton} from '../components/LinkButton'
请注意,该文件使用 webpack 编译正常,这只是一个 linting 问题。
谢谢!
【问题讨论】:
-
为什么不直接使用 es2017 的导出默认/导入语法?
-
我也试过了,同样的问题。我认为更明确可能会有所帮助,但没有......
标签: javascript vue.js vuejs2 eslint