问题描述
从VueCLI迁移到Vite之后,据我所知,我必须“手动”进行掉毛;如我错了请纠正我。 因为我只想整理.ts和.html文件(甚至将它们分开,所以我也将它们分开),所以我的程序包json中有以下脚本:
"lint": "eslint --ext .ts --ext .html src/"
它发现了一些问题,例如循环中缺少:key
,但它也向我显示了每个模板的错误:
错误清除vue /注释指令
这始终是我template.html中任何根元素的结束标记 如果只有一个根元素,则该文件将得到一个警告;如果有多个根元素,则每个结束标记都将得到一个警告。
我不理解此规则的抱怨,因为它的documentation上有禁止eslint的注释,而我的模板中没有这些注释。
解决方法
我遇到了同样的问题,但是在eslint的nuxt中,我只需要更新eslint-config和eslint-module:
"@nuxtjs/eslint-config": "^5.0.0","@nuxtjs/eslint-module": "^3.0.1",
来源:https://github.com/nuxt/eslint-plugin-nuxt/issues/121
,我刚刚更新了我的npm依赖项,并且遇到了相同的错误。
我正在阅读eslint文档,最后我意识到,如果您在false error
配置文件中设置规则,则可以删除.eslintrc.js
。
这是我的.eslintrc.js
配置文件:
module.exports = {
root: true,env: {
browser: true,node: true
},parserOptions: {
parser: 'babel-eslint'
},extends: [
'@nuxtjs','prettier','prettier/vue','plugin:prettier/recommended','plugin:nuxt/recommended'
],plugins: [
'prettier'
],// add your custom rules here
rules: {
"vue/comment-directive": 0
}
}
添加规则"vue/comment-directive": 0
,即!,错误消息已删除!。
可能的值为:
- 0表示
disabled
- 1表示
warning
- 2表示
error
尝试在您的IDE中将其更改为工作方式
(就我而言,每次更改此配置文件中的值时,我都必须停止服务器并重新运行它。)
,在.eslintrc.js上设置此代码段
color
解决我的问题,我想知道为什么。来自documentation
的解决方案节点v12.20.0
,我有同样的错误。 我被教了如何解决这个错误。 https://qiita.com/tashinoso/items/a72741ca8e2fd928ca77#comment-3e6cd674353056ecbb3a
module.exports = {
...
overrides: [
{
files: ["*.vue"],processor: "vue/.vue"
}
]
}
,
这是一种对我有用的临时修复方法,我认为它也对你有用。
vue/评论指令
该规则包含在“plugin:vue/base”、“plugin:vue/essential”、“plugin:vue/vue3-essential”、“plugin:vue/strongly-recommended”、“plugin:vue”中/vue3-strongly-recommended”、“plugin:vue/recommended”和“plugin:vue/vue3-recommended”。
ESLint 不提供任何 API 来增强 eslint-disable 功能,并且 ESLint 规则不能影响其他规则。但是 ESLint 提供了处理器 API。
此规则将所有类似 eslint-disable 的注释作为错误发送到 .vue 文件处理器的后处理,然后后处理删除所有 vue/comment-directive 错误和禁用区域中报告的错误。>
您需要做的就是添加 eslint-disable-next-line vue/component-tags-order 此行作为上面的注释,您在每个块中的标签内使用注释的任何地方都需要指定是否添加注释。
有关更多信息,请访问:- https://eslint.vuejs.org/rules/comment-directive.html