A
A
Andrej Sharapov2019-12-08 15:07:04
Vue.js
Andrej Sharapov, 2019-12-08 15:07:04

Template to template?

Hi all! I apologize in advance for possibly stupid questions.
1. is it possible to use template in template in vue component?

<template v-for="">
<h1></h1>
<p></p>
<template v-for="">
<div></div>
...
</template>
</template>

If this is not possible, then what is the right way? I have a component whose data is in json (about 15 values). Many of them require adjustments with v-for and v-if/else. What is the best thing to do in order not to load everything into one template, but also not to split the component into 15 or more subcomponents? Or is it better to break?
2. Is it possible to influence the parent from a child component? For example, if I use pug variables and I need to change the background color. In the parent I specify - var bgpage; , and I write value in child components? It didn't work for me, but is there a way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
�
ⓒⓢⓢ, 2019-12-08
@Madeas

1. is it possible to use template in template in vue component?

Yes
yes, for example, $emit('my-event')events from a child, in the parent we catch on an element with a tag@my-event=""
if your pug is not running in realtime, then you can't.
First, pug is executed and html is collected
. Then vue is executed on the Already assembled html
(that is, in the assembled HTML there will no longer be pug variables and other declarations)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question