Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

180
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda