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

290
Vistas
Using async computed properties inside of another computed property?
export default {
   data(){
      return {
         users: [] // async data called in create or mounted hook
      }
   },
   computed: {
      filteredUsers() {
         return this.users.filter(el => el === 'red')
      }
      someFunction() {
         // 1. this does not work 
         const result = this.users.filter(el => el === 'red')
         console.log(result) // undefined

         // 2. this works
         console.log(this.filteredUsers)
      }
   }
}

In the example, #1 is undefined because users is initially empty. Which I understand.

How come I do not have to put a conditional or a check to see if filteredUsers exists when using in another computed? How does Vue handle this logic internally?

As the users array changes, the computed filteredUsers will change. And when this changes I'm assuming the other computed properties will refresh?

I'm fairly new to Vue so curious if there are any caveats to using computed within computed?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can directly use this.filteredUser() inside your someFunction(). Vue caches the computed property and if the source data changes it cache it again and do not do any computing for the same computed call. Here is a part from Vue document "computed properties are cached based on their reactive dependencies." This is probably why you are having this issue.

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