惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
G
Google Developers Blog
J
Java Code Geeks
C
Check Point Blog
Last Week in AI
Last Week in AI
Microsoft Azure Blog
Microsoft Azure Blog
Blog — PlanetScale
Blog — PlanetScale
月光博客
月光博客
Vercel News
Vercel News
The GitHub Blog
The GitHub Blog
L
LangChain Blog
有赞技术团队
有赞技术团队
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
博客园 - 司徒正美
IT之家
IT之家
Martin Fowler
Martin Fowler
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
U
Unit 42
Jina AI
Jina AI
Microsoft Security Blog
Microsoft Security Blog
I
InfoQ

博客园 - zhouyu

shardingsphere实现按月分表 Vue3手册译稿 - 深入组件 - 插槽 Vue3手册译稿 - 深入组件 - 自定义事件 Vue3手册译稿 - 深入组件 - 非prop属性 Vue3手册译稿 - 深入组件 - pros Vue3手册译稿 - 深入组件 - 组件注册 Vue3手册译稿 - 基础 - 组件基础 Vue3手册译稿 - 基础 - 表单输入绑定 Vue3手册译稿 - 基础 - 事件处理 Vue3手册译稿 - 基础 - 列表渲染 Vue3手册译稿 - 基础 - 条件渲染 Vue3手册译稿 - 基础 - Class和Style绑定 Vue3手册译稿 - 基础 - 计算属性及监听器 Vue3手册译稿 - 基础 - Data属性及方法 Vue3手册译稿 - 基础 - 模板语法 Vue3手册译稿 - 基础 - 应用&组件实例 Vue3手册译稿 - 基础 - 介绍 Vue3手册译稿 - 基础 - 安装 元旦三天假期,实现一个电商退单管理系统【四】-手机客户端实现
vscode Vue3 多根节点语法检验错误fix
zhouyu · 2021-03-23 · via 博客园 - zhouyu

错误

众所周知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