A
A
AkifPetrov2018-12-24 10:35:53
Vue.js
AkifPetrov, 2018-12-24 10:35:53

How to organize a poll of dynamically created components through v-for?

Hello, I am creating a list of components like this:

<component :is="feature.class" :key="feature.id" v-for="feature in features"></component>

Inside the component, I can have one or more different inputs
. Also, inside the components, I want to organize a getData method that will return data.
Tell me, how can I get a list of all in the parent, access each of them and call getData inside to get all the data?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
0
0xD34F, 2018-12-24
@AkifPetrov

Add ref="features"to your list, getting data will look something like this:

this.$refs.features.forEach(n => console.log(n.getData()))

A
Anton Anton, 2018-12-24
@Fragster

IMHO, it's time to switch to the event bus (if the methods are asynchronous - to start polling, and plugin-type components - they themselves implement different methods for obtaining data, well, or the application uses the actor model) or vuex, if the dependencies are somewhat more rigid.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question