Component template should contain exactly one root element.

本文讨论了在Vue组件开发中遇到的错误——Component template should contain exactly one root element。解释了该错误意味着组件模板需要一个根元素来包裹所有内容,并提供了错误代码示例及其修正方法。

vue组件化开发遇到的问题,问题描述:

(Emitted value instead of an instance of Error)
  Error compiling template:

  <MainHeader/>
  <MainSearch/>

  - Component template should contain exactly one root element. If you are using v-if on multiple elements, use v-else-if to chain them i
nstead.


 @ ./src/components/content/main/MainBody.vue 11:0-376
 @ ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script&index=0!./src/App.vue
 @ ./src/App.vue
 @ ./src/main.js
 @ multi (webpack)-dev-server/client?http://localhost:8080 webpack/hot/dev-server ./src/main.js

每次遇到一大串英文报错就头疼,就欺负我这种vue小白,英语渣渣。冷静下来(用翻译软件)翻译一下其中最关键的一句话

Component template should contain exactly one root element.:
组件模板应该只包含一个根元素。

就是多个组件之间必须有一个根元素,不能直接使用,并且也标明了报错的位置:

Error compiling template:

  <MainHeader/>
  <MainSearch/>

原来错误的代码:

<template>
    <MainHeader/>
    <MainSearch/>
</template>

修改后正确的代码:

<template>
  <div>
    <MainHeader/>
    <MainSearch/>
  </div>
</template>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值