【异常处理】Vue报错 Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

问题描述

启动VUE项目后控制台报错:

    Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them instead.

翻译为:组件模板应该只包含一个根元素

查看vue代码,发现template中有两个元素,所以报错

解决方案

将h1标签放到div里面即可

posted @ 2022-03-11 16:50  weiambt  阅读(412)  评论(0)    收藏  举报