码迷,mamicode.com
首页 > 其他好文 > 详细

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 01:08:57      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:一个   span   ges   one   blog   roo   jpg   logs   解决办法   

出现这种错误的原因是因为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.

标签:一个   span   ges   one   blog   roo   jpg   logs   解决办法   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!