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

146
Visualizações
Problem assigning data from onSnapshot firestore to a Vue ref variable

Me and my friends are using Vue with firestore to create some functionality. This is our first experience using either and we are having some trouble. We are now trying to add a onSnapshot to a doc on firestore and assign said data to a vue ref variable thus making it possible to use a watcher and respond to changes.

As can be seen in the image our doc contains 2 arrays which is the data we need to reach after a change has been observed by the onSnapshot. Our problem is that we dont know how to assign gameData to the appropriate data so that we can reach and use a watcher outside of the function. Datastructure on firestore

export function realTimeGame(lobbyId) {

    const gameCollection = firestore.collection('lobbies/' + lobbyId + '/game_data');

    const gameData = ref([]);
    const unsubscribe = gameCollection.doc('gameThings').onSnapshot(snapshot => { 
        // gameData.value = snapshot.map(document => ({ id: document.id, ...document.data() })) .map is not defined
        gameData.value = snapshot; //this is essentially what we want to do
    });
    onUnmounted(unsubscribe)
    return { gameData }
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

We found a solution:

 export function realTimeGame(lobbyId) {
    const gameData = ref();
    const unsub = onSnapshot(doc(firestore,'lobbies/' + lobbyId + '/game_data/gameThings'),(doc) => {
        gameData.value = { ...doc.data()} 
    })
    onUnmounted(unsub)
    return gameData
}
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