I
I
Ismail942020-12-04 10:46:31
Vue.js
Ismail94, 2020-12-04 10:46:31

How to send data to child component?

I'm from b.d. I get an array of the descendants of the given user, how can I pass them to the child component. Now if I pass it like in the code, then an empty array is passed in the child component. How to transfer?

data(){
        return{
            partnerChildren: [], //Массив с данными потомков партнера
        }
    },

    methods: {
        //Получаем всех потомков данного партнера
        getChildrenPartner(){
            axios.get('/auth/getChildrenPartner/' + this.$auth.user().inp).then((response)=>{
                this.partnerChildren = response.data.children;
            });
        },
    },

    mounted() {
        Event.$emit('partnerChildren', this.partnerChildren)
    },

    created(){
        //Получим всех потомков партнера
        this.getChildrenPartner();
    },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2020-12-04
@Kozack Vue.js

The parent component should not render the child until enough data has loaded for the child. Something like this:

<template>
  <child-component v-if="partnerChildren && partnerChildren.length"></child-component>
  <p v-else-if="partnerChildren === null">Загрузка ...</p>
  <p v-else>У партнера нет потомков</p>
</template>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question