Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

102
Views
What causes this failure to pass an object from the main component to a child component in a Vue 3 app?

I am working on a Vue 3 app. I have run into a problem working with a component and one of its <User /> subcomponent.

In App.vue:

<template>
  <Navbar />
  <Sidebar />
  <Content 
    title="Users"
  />
  <Footer />
</template>

<script>
import Navbar from './components/Navbar.vue'
import Content from './components/Content.vue'
import Sidebar from './components/Sidebar.vue'
import Footer from './components/Footer.vue'

export default {
  name: 'App',
  components: {
    Navbar,
    Content,
    Sidebar,
    Footer  
  },

  data() {
    return {
      url: 'https://jsonplaceholder.typicode.com',
      users: [],
    }
  },
  async mounted() {
    // Users
    await this.axios.get(`${this.url}/users`).then((response) => {
      if (response.data.code == 200) {
        this.users = response.data.data;
        console.log(this.users);
      }
    }).catch((errors) => {
      console.log(errors);
    });
  }
}
</script>

In Navbar.vue:

<template>
  <a class="navbar-brand" href="#">My App</a>
  <User :users='users' />
</template>

<script>
import User from './User.vue'

export default {
  name: 'Navbar',
    components: {
        User
    }
}
</script>

In User.vue, I try to output the user's full name fis way, since typeof(users) retuens object:

<template>
    {{ users.firstName }} {{ users.lastName }}
</template>

<script>
export default {
  name: 'User',
    props: {
    users: Object
  }
}
</script>

The problem

I get this error in the console: Uncaught TypeError: Cannot read properties of undefined (reading 'firstName').

Where is my mistake?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

//in Navbar

<template>

  <a class="navbar-brand" href="#">My App</a>

    <User :users='usersData' />

</template>    

<script>
import User from './User.vue'

export default {
  name: 'Navbar',
    components: {
        User
    },
props:['usersData']
}
</script>

//in App.vue

<template>
  <Navbar :usersData="users" />
  <Sidebar />
  <Content 
    title="Users"
  />
  <Footer />
</template>
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!