A
A
AspMaster2019-09-27 10:10:52
Vue.js
AspMaster, 2019-09-27 10:10:52

How to pass a component from parent to child?

I have a homepage component. On this page I want to display a table with data. I have created a generic table component that I would like to use on other pages as well. However, on other pages, I will need to display other objects, respectively, the number of columns, their names will change. To do this, I decided to create a row component for each type used, but how can I send the row component that I need to display this time to the table component?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mr. Grump, 2019-09-27
@AspMaster

Use the slot system:
In the table component:

...
<tr v-for="row in rows">
  <td v-for="header in headers">
    <slot :name="`cel_${header.key}`" :row="row"> {{ row[header.key] }} </slot>
  </td>
</tr>
...

Using the table component:
...
<table-component :rows="users" :headers="headers">
  <template slot="cel_full_name" slot-scope="props">
    <router-link :to="`/user/${props.row.id}`">{{ props.row.full_name }}</router-link>
  </template>
</table-component>
...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question