前言

报错信息:

成功解决Component template should contain exactly one root element_视频教程

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

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

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

查看代码

成功解决Component template should contain exactly one root element_视频教程_02

如图所示,template下面包含了两个<div>根节点,这是报错的根本原因。

解决

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

成功解决Component template should contain exactly one root element_报错信息_03

OK, GAME OVER

更多精彩内容请关注:程序员高手之路

回复“vue项目”,免费获取以下项目视频教程

成功解决Component template should contain exactly one root element_报错信息_04

成功解决Component template should contain exactly one root element_报错信息_05