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

174
Views
How do I return variables in watchEffect from vue 3 setup function
setup(props) {
  const id = ref(props.id)
  watchEffect(() => {
    const { data1, data2, data3 } = getData(id)
  })

  return { data1, data2, data3 }
}

This is just a portion of the code, the watchEffect, ref and getData are all imported but the return function below says data1, data2, data3 are undefined, why is that?

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

0

Declare refs outside the function:

setup(props) {
  const id = ref(props.id);
  const data1 = ref(null);
  const data2 = ref(null);
  const data3 = ref(null);

  watchEffect(() => {
    [data1.value, data2.value, data3.value] = getData(id)

  })

  return { data1, data2, data3 }
}

And if you return an object:

setup(props) {
  const id = ref(props.id);
  const data1 = ref(null);
  const data2 = ref(null);
  const data3 = ref(null);

  watchEffect(() => {
    {
      data1: data1.value,
      data2: data2.value,
      data3: data3.value
    } = getData(id)

  })

  return { data1, data2, data3 }
}

I don't have the rest of your code but I'm sure it can be more optimized...

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!