成功解决Component template should contain exactly one root element

简介: 成功解决Component template should contain exactly one root element

前言

报错信息:

VUE小白会碰到这样的错误,刚上手,对vue还不太熟悉,所以对里面的构造方式不太清楚。

对于这个bug,我们很容易翻译为:

组件模板应该只包含一个根元素

查看代码

如图所示,template下面包含了两个

根节点,这是报错的根本原因。

解决

在最外层写一个div,把所有的前端代码放进去就好了:

OK, GAME OVER


相关文章
|
5月前
|
JavaScript 索引
Component name “index“ should always be multi-word vue/multi-word-component-names
Component name “index“ should always be multi-word vue/multi-word-component-names
|
6月前
|
JavaScript
error Component name “Login“ should always be multi-word vue/multi-word-component-names【已解决】
error Component name “Login“ should always be multi-word vue/multi-word-component-names【已解决】
374 1
|
5月前
【vue3】Argumnt of type ‘history:RouterHistory;}is not assignable to paraeter of type ‘RouterOptions‘.
【vue3】Argumnt of type ‘history:RouterHistory;}is not assignable to paraeter of type ‘RouterOptions‘.
104 0
|
7月前
Angular启动/node_modules/@types/node/index.d.ts (20,1): Invalid ‘reference‘ directive syntax.
Angular启动/node_modules/@types/node/index.d.ts (20,1): Invalid ‘reference‘ directive syntax.
85 2
Unknown custom element: <add-employee> - did you register the component correctly? For red cursive c
原因: 1.组件名没写对(导入和注册不对应) 2.components少写了个s 3.组件命名最好是驼峰命名 4.导入时语法错误 5.代码中有两个components,后一个的值把前一个覆盖了 6.组件直接循环套用了
104 0
|
7月前
|
JavaScript 前端开发
[Vue Router warn]: Component “default“ in record with path “/xx“ is a function that does not return
[Vue Router warn]: Component “default“ in record with path “/xx“ is a function that does not return
1346 0
|
7月前
|
前端开发 开发者
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
TS7031: Binding element ‘role‘ implicitly has an ‘any‘ type.
95 1
|
7月前
|
JavaScript
【Vue Error】 error Component name “product“ should always be multi-word vue/multi-word-compone……
【Vue Error】 error Component name “product“ should always be multi-word vue/multi-word-compone……
|
7月前
|
JavaScript
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
[Vue warn]: Method “components“ has type “object“ in the component definition. Did you reference the
|
JavaScript
[Vue warn]: Unknown custom element: <Top> - did you register the component correctly?
[Vue warn]: Unknown custom element: <Top> - did you register the component correctly?

热门文章

最新文章