A
A
Arseny Sokolov2017-09-05 13:43:05
webpack
Arseny Sokolov, 2017-09-05 13:43:05

How to add multiple components inside a Vue component?

There is a component, let's say it's called Home.vue, it contains the following code:

<template>
    <banner></banner>
    <services></services>
</template>

If you use only one component inside this component, then everything works, as soon as you try to use more than one component, the project is not built and throws out an error:
(Emitted value instead of an instance of Error)
  Error compiling template:

  <banner></banner>
  <services></services>

  - 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.

How to force to use several components inside this or any other component?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Stanislav Pochepko, 2017-09-05
@ArsenBespalov

Wrap everything in a div

<template>
<div>
    <banner></banner>
    <services></services>
</div>
</template>

There must be only one root element inside the template tag

A
Alexander Aksentiev, 2017-09-05
@Sanasol

should contain exactly one root element

what's incomprehensible?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question