• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

151
Views
How can I get stored value in Vue 3?

I want to get the value of my stored user from my store

but when I tried on onMounted function

onMounted(async () => {
       console.log('user', store.state.user)  //here i can see the values
        const info = computed(() => {
        return store.state.user
      })
      console.log('info', info)

it does not give the information, I am getting info.name undefined

what happening here?

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

0

info is a ref, it cannot have info.name. It's a mistake to use computed inside mounted hook, it should be directly inside setup:

const info = computed(() => store.state.user)

onMounted(async () => {
      console.log('info', info.value)
});

store.state.user value is not guaranteed to be up-to-date at the time when it's accessed. In case it changes during the component's lifespan, it needs to be accessed inside a watcher or another computed property.

about 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error