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

142
Views
How to access props passed inside a setup function for Vuejs (Composition API)

When I use props to pass an object into the child component, I am unable to use the props inside the setup function (Composition API). I am trying to use the props to run a query from the firebase using the displayName property of the user instead of using 'Abe'. I am new to Vue, please help me out!

<template>
  <div v-if="user">
      <Process :user="user"/>
  </div>
  <div v-else>
      <h1>Loading user</h1>
  </div>
</template>

<script>
import Process from '../views/Process.vue'
import getUser from '@/composables/getUser'
export default {
    components: { Process },
    setup(){
        const { user } = getUser();
    
        return {user}
    }

}
</script>

Using user in the setup function gives an undefined error but using it at top of the template returns the correct object.

<template>
  <p>Process Payroll</p>
  <h1>{{ user.displayName }} </h1>
  <h1>{{ docs }} </h1>
</template>

<script>
// import getUser from '@/composables/getUser'
import { ref, onMounted, watch } from 'vue'
import { projectFirestore, projectAuth } from '@/firebase/config'
import { useRouter, useRoute } from 'vue-router'

export default {
    props: ['user'],
    setup() {
    // const { user } = getUser();

    // watch(()=> user, () => returnUser())

    const lastName = ref("");
    const firstName = ref("");
    const docs = ref("");

    const returnUser = async () => {
        const res = await projectFirestore
            .collection("users")
            .where("displayName", "==", "Abe") // Case sensitive
            .get();

        const lastNameList = res.docs.map(d => `Abe ${d.data().lastName}`)
        console.log(lastNameList)
        console.log(user)
        console.log(user.displayName)
        docs.value = lastNameList;
    }

    onMounted(returnUser)

    return { docs, returnUser};
  },
}
</script>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Pass props to setup function:

setup(props) {
....
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!