首页 > 其他 > 详细

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.

时间:2017-09-03 00:53:26      阅读:7725      评论:0      收藏:0      [点我收藏+]

出现这种错误的原因是因为Vue的模板中只能有一个根节点,所以在<template>中尝试插入第二个元素时就会报这个错。

例如:

HTML:

<template>
    <p>{{msg}}</p>
    <p>{{msg}}</p>
</template>

 

结果:

技术分享

 

解决办法:

将<template>中的元素用一个<div>包裹起来即可。

 

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.

原文:http://www.cnblogs.com/Dengxiaobo/p/7468505.html

(0)
(2)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!