Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Invalid prop: type check failed for prop "data". Expected Array, got Object

I'm new to vuejs and trying to use the buefy library.

Error :

Invalid prop: type check failed for prop "data". Expected Array, got Object

<template>
    <b-table :data="data" :columns="columns"></b-table>
</template>

<script>
    export default {
        data() {
            return {
                data: this.data,
                columns: [
                    {
                        field: 'name',
                        label: 'Name',
                    },
                ]
            }
        },
        mounted() {
            axios
            .get('/test')
            .then(
                response => (this.data = response)
            )
        }
    }

</script>

The json content:

[{"name":"test"}]

What did I miss? Thx :)

like image 605
Thomazzi Avatar asked Oct 26 '25 09:10

Thomazzi


1 Answers

The declaration of data property should be as below:

 data: []

Updated code:

<script>
export default {
    data() {
        return {
            data: [],
            columns: [
                {
                    field: 'name',
                    label: 'Name',
                },
            ]
        }
    },
    mounted() {
        axios
        .get('/test')
        .then(
            response => (this.data = response)
        )
    }
}
</script>
like image 186
Riddhi Avatar answered Oct 27 '25 23:10

Riddhi



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!