S
S
Sport-code2019-05-24 18:43:04
Vue.js
Sport-code, 2019-05-24 18:43:04

Why is data not being passed to the component?

Hello!
Can anyone advise please?
I don’t understand the data I get from the server, I checked everything is fine, I
insert them into the app-analytics-chart component, I get undefined for some reason?

<template>
<div>
    <h1>Аналитика по заказам</h1>
    <app-analytics-chart 
        title="месяц" 
        :labels="months" 
        :data="analytics.countOrdersByMonth" />

</div>
</template>

<script>
import AppAnalyticsChart from '@/components/pages/admin/AnalyticsChart'
import moment from 'moment'

export default {
    components: {
        AppAnalyticsChart
    },
    data: () => ({
        analytics: [],
    }),    

    mounted() {
        this.loadOrders()
    },

    methods: {
        async loadOrders() {
            try {
                const res = (await this.$http.get('/analytics')).data
                this.analytics = res
                // console.log(res);

            } catch (error) {

            }
        }
    }    
}
</script>

in the component I get analytics.countOrdersByMonth = undefined

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2019-05-24
@Sport-code

Or maybe you don’t need to render the component until the data has arrived? Then undefined will not be passed.

<app-analytics-chart v-if="analytics.countOrdersByMonth"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question