A
A
Alexey2021-06-30 11:26:08
Vue.js
Alexey, 2021-06-30 11:26:08

How to load different templates in a Vue component, leaving the contents of the JS code untouched?

Good day!

I have a Vue component. Depending on the situation, it is necessary to load different template code into the section, while leaving all the JS untouched. You can of course do something like this:

<template>
  <div v-if="situation1">
    (шаблон 1)
  </div>
  <div v-else>
    (шаблон 2)
  </div>
</template>
<script>
  (одинаковый код для обоих шаблонов)
</script>


The problem is that template versions, in addition to having very different layouts, are also large enough to shove them into one file. It's inconvenient to manage it. I would like something like importing by condition. I didn't find it in the dock.
Is there any solution other than the above?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2021-06-30
@kulakoff Vue.js

<template>
  <div>
    <component :is="ComponentDependingOnTheCondition">
  </div>
</template>
<script>
  (одинаковый код для обоих шаблонов)
</script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question