K
K
kroha30002020-03-06 12:49:15
Vue.js
kroha3000, 2020-03-06 12:49:15

Is it possible to use several templates at once within one single VueJS component and how to call them?

Is it possible to place several templates inside one component?

<template>
  <div>
    1-ый
  </div>
</template>

<template>
  <div>
    2-рой
  </div>
</template>


and if possible, how to display the required template ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex, 2020-03-06
@kroha3000

No. It is forbidden. Move them into subcomponents.
RFC

A
Andrew, 2020-03-06
@AndrewRusinas

It would be good practice to create separate components and combine them into one parent, where they will be dynamically imported, and the "component(:is="<desired component>") element will be responsible for displaying the desired component. I want to create files, I don’t understand why not do this:

<template>
  .component-1(v-if="blah")
     // код компонента
  .component-2(v-else-if="blah-blah")
     // код второго компонента
  // и так далее
</template>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question