Vue出现Component template should ...

当运行vue出现错误Component template should contain exactly one root element. If you ...的时候,我们只需要将<template>标签中的代码包裹到<div>标签中即可。


报错代码

点击查看代码
<template>
    <h1>Hello World</h1>
</template>

改为这样才不会报错

点击查看代码
<template>
  <div class='hello'>
    <h1>Hello World</h1>
  </div>
</template>
posted @ 2021-09-26 14:13  Yunjiang  阅读(140)  评论(0)    收藏  举报