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>中尝试插入第二个元素时就会报这个错。

例如:

HTML:

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

 

结果:

技术分享

 

解决办法:

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

 

文章来自:http://www.cnblogs.com/Dengxiaobo/p/7468505.html
© 2021 jiaocheng.bubufx.com  联系我们
ICP备案:鲁ICP备09046678号-3