Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
Loaded fields are not initialized in the additional function

I use two functions to load some components for my page and save it in two fields representatives and allUsers. Then I try to use additional func subtractSets() to a little bit modify loaded data. My problem is that fields this.representatives and this.allUsers in this adittional function are still not initialized. What I can do to get loaded data in subtractSets()?

setup() {
     const representatives = ref([])
     const allUsers = ref([])
 data() {
   return { 
     representatives,
     users
   }
 }
},

methods(): {
   loadUsersRepresentatives() {
       axios.get('getRepresentatives').then(res => {
            this.representatives = res.data
        }).catch(() => {
            ...
            })
        });
     },
     loadAllUsers() {
         axios.get('/getAllUsers').then(res => {
         this.allUsers = res.data
         }).catch(() => {
             ...
             })
         });
    },
    subtractSets(obj1, obj2) {
            ...
    },
    showRepresentativesDialog(facultyID) {
          this.loadUsersRepresentatives(facultyID)
          this.loadAllUsers()
          this.subtractSets(this.representatives, this.allUsers)
          this.representativesDialog = true
      }
},
´´´
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You are missing async / await

methods(): {
   async loadUsersRepresentatives() {
       return axios.get('getRepresentatives').then(res => {
            this.representatives = res.data
        }).catch(() => {
            ...
            })
        });
     },
     async loadAllUsers() {
         return axios.get('/getAllUsers').then(res => {
           this.allUsers = res.data
         }).catch(() => {
             ...
             })
         });
    },
    subtractSets(obj1, obj2) {
            ...
    },
    async showRepresentativesDialog(facultyID) {
          await this.loadUsersRepresentatives(facultyID)
          await this.loadAllUsers()
          this.subtractSets(this.representatives, this.allUsers)
          this.representativesDialog = true
      }
},
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda