学无先后,达者为师

网站首页 Vue 正文

Vue报错:Error compiling template: Component template should contain exactly one root element. If you

作者:小吴同志你好呀 更新时间: 2022-02-20 Vue

问题描述
Error compiling template:

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.
大致意思是:错误编译模板:
组件模板应该只包含一个精确的根元素。如果您使用v-if在多元素模板,请替换使用v-else-if来链接它们…

问题代码
在这里插入图片描述
解决办法:所以这里template模板下应该只包含一个标签元素,而不是两个甚至多个。修改之后的正确代码如下:

<template id="cpn">
    <div>
        <p>{{cmovies}}</p>
        <h2>{{cmessage}}</h2>
    </div>
</template>

原文链接:https://blog.csdn.net/baidu_38742725/article/details/106828323

栏目分类
最近更新