vscode Vue3 多根节点语法检验错误fix

错误

众所周知vue3支持多个根节点,但在vscode中eslint检查会针对多根节点报错。虽然不影响使用,但看着很不舒服:
The template root requires exactly one element.

image

fix方法

项目根目录下.vscode目录,有一个settings.json的文件(如果没有则新建之)
加入一行:
"vetur.validation.template": false
不进行模板检查。可以不提示这个错误了。但模板检查也失去了。

github上有哥们忍不住发问:

Disable the whole template validation for the sake of fixing one warning? Is that a suggestion?

这个建议确实不是bestway,然后有下面有哥们回复

The Vue 3 rules are now automatically used when Vue3.
You don't need disable it now.

And If you use eslint in project, you can disable it.
Let your project eslint replace it.
The two functions are the same.
https://vuejs.github.io/vetur/linting-error.html#linting

上面这个链接挂了。确实eslint已支持vue3的语法检查了,为何还会提示这个错误呢?

再往下看:

Disabling the template validation defeats the whole purpose of having Vetur.

I resolved the issue by moving the project to the root of the workspace. So if you're project is in a subfolder (e.g workspace > subfolder > project), Vetur looks for the package.json file in the subfolder and not in your project folder, hence the reason why it doesn't work properly.

果不其然,我的项目在子目录下,我重新用vscode打开项目后,错误消失了。

参考

https://github.com/vuejs/vetur/issues/1976

posted on   zhouyu  阅读(1088)  评论(0编辑  收藏  举报

编辑推荐:
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
阅读排行:
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
· SQL Server 2025 AI相关能力初探

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示