【异常处理】Vue报错 Component template should contain exactly one root element.

问题描述

启动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里面即可

相关推荐
ruanCat1 小时前
Prettier 明明执行成功,Markdown 为什么还是没变?一次插件误诊复盘
前端·javascript·node.js
软件开发技术深度爱好者2 小时前
在线学习实践 TypeScript 的官方Playground(演练场)使用介绍
javascript·学习·typescript