当前位置:首页 > 未分类

Component template should contain exactly one root element. If you are using v-if on multiple eleme

admin8个月前 (02-23)未分类448

情境描述

今天使用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.

到百度翻译成中文的意思是

组件模板应正好包含一个根元素。如果在多个元素上使用v-if,请改用v-else-if来链接它们。

错误发生原因

每一个vue文件就是vue组件,在vue组件当中,有一条规定,就是,template标签只能有一个儿子,不能有多个儿子,也就是说,以下的写法是错误的。

<template>  
    <home-title></home-title>
    <flist-content></flist-content>
    <page></page>
</template>

正确的是,我们应该使用一个大盒子将这三个组件都包裹起来,这里的大盒子,我使用div元素来描述。比如这样:

<template>
    <div>
        <home-title></home-title>
        <flist-content></flist-content>
        <page></page>
    </div>
</template>

小结:

记住,template只能有一个儿子,但是,template可以有n多个孙子。


原文链接:https://blog.csdn.net/weixin_39553363/article/details/104151953

扫描二维码推送至手机访问。

版权声明:本文由前端开发技术分享发布,如需转载请注明出处。

本文链接:https://www.jqkcms.fun/?id=16

分享给朋友:

相关文章

同时使用requireJS和Layui时,解决在html文件中Layui扩展模块加载报错

前言部分后台管理框架使用Layui作为前端,并且使用了requireJS,期间可能出现的加载Layui扩展模块加载不了,或加载报错的问题。若无法加载或报错模块不是前言中提到的模块,可直接参考后面的解决思路。本次解决的问题的前提:1,使用requireJS;2,使用Layui;…

VUE开发报错:Avoid mutating a prop directly since the value will be overwritten whenever the parent ...

VUE开发报错:Avoid mutating a prop directly since the value will be overwritten whenever the parent component re-renders. Instead, use a data or computed p…

微信小程序 -- 由于隐私协议未设置,影响隐私相关api调用

在app.json中,usePrivacyCheck设置为false,可以免除在开发者工具中调试时的影响,开发版暂未测试。…

uni-app 编译出来的微信小程序中自定义组件没有wxss

经查阅官方文档得知,符合uniapp规则的自定义组件,不需要引用以及注册,详见:https://uniapp.dcloud.net.cn/component/#easycom解决方案:…

VUE开发报错:Module build failed (from ./node_modules/ ...

VUE开发报错:Module build failed (from ./node_modules/@dcloudio/vue-cli-plugin-uni/packages/vue-loader/lib/loaders/templateLoader.js):  语法错误: Une…