0

I am receiving a json listing, and I am sending this to a component

const app = new Vue({
el: '#app',
data: {
    tablaUsuarios: []
},
mounted() {
    axios.get(url + 'listar/')
        .then(res => {
            this.tablaUsuarios = res.data
        })
        .catch(err => {
            console.error(err);
        })
}
})

Vue.component('tabla-usuario', {
props: ['listaUsuarios'],
template:`<div class="table-responsive">
        <table class="table table-hover text-center">
            <thead>
                <tr>
                    <th>Nombre</th>
                    <th>Correo</th>
                    <th>Password</th>
                </tr>
            </thead>
            <tbody>
                <tr v-for="usuario in listaUsuarios">
                    <td> {{ usuario.nombre }}</td>
                    <td> {{ usuario.correo }}</td>
                    <td> {{ usuario.password }}</td>
                </tr>
            </tbody>
        </table>
    </div>` 
  })

In the html

<tabla-usuario :listaUsuarios="tablaUsuarios"></tabla-usuario>

Technically this is how it should work the problem is that in the DOM it shows me like this

<div class="table-responsive" listausuarios="[object Object],[object Object],[object Object],[object Object],[object Object]">
        <table class="table table-hover text-center">
            <thead>
                <tr>
                    <th>Nombre</th>
                    <th>Correo</th>
                    <th>Password</th>
                </tr>
            </thead>
            <tbody></tbody>
        </table>
    </div>

Could someone who knows the subject tell me what the problem is?

4
  • Could you log the value of res.data? Are you getting anything? Commented Aug 9, 2020 at 5:10
  • yes, in res.data comes the json with the list of my data Commented Aug 9, 2020 at 7:02
  • From the error, it seems like it's returning an array within an array or something. Could you show the structure of the list? You could replace real data with fake data, to protect privacy. Also, I am curious at to why listausuarios attribute is showing in the DOM and not listaUsuarios as the props are. Could there be a spelling error there? Commented Aug 9, 2020 at 12:05
  • ok I realized that if I had a spelling mistake I can't put the prop as listaUsuarios if not like listausuarios Commented Aug 9, 2020 at 20:51

1 Answer 1

1

Your prop name in the html template needs to be kebab-case (https://v2.vuejs.org/v2/guide/components-props.html)

like so:

<tabla-usuario :lista-usuarios="tablaUsuarios"></tabla-usuario>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.