T
T
Tenebrius2017-08-18 11:17:44
Vue.js
Tenebrius, 2017-08-18 11:17:44

[vue.js] How to embed a component within a component?

Let's say I want to get the following structure as a result:

<!-- первый компонент - parent -->
<div id='parent'>
<h1>Title</h1>

<!-- второй компонент - child -->
<ul id='child'>

<!-- несколько третьих компонентов - grandchild -->
<li class='grandchild'><span>smth</span></li>
<li class='grandchild'><span>smth</span></li>
<li class='grandchild'><span>smth</span></li>

</ul>

</div>

Also, let's say I registered these three component types:
Vue.component('parent', {/* code */});
Vue.component('child', {/* code */});
Vue.component('grandchild', {/* code */});

How to make the parent component have 1 child component which has an array of grandchild components ?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Kulakov, 2017-08-18
@Tenebrius

// child template
<template>
<ul>
<slot></slot>
</ul>
</template>

<parent>
<child>
  <granchild  v-for="item in items"></grandchild>
</child>
</parent>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question