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

209
Visualizações
not able to render element into screen by v-for

I got data from a DB, stored it in an array, but could not render it with V-For, neither did I get any error or warning. I have following data on my db:

enter image description here

and here is my code:

<template>
  <div v-for="item in userList" :key="item.uid">
      <p>{{item.fullName}}</p>
  </div>
</template>
<script>
import { db } from "src/boot/firebase";
import { collection, query, where, getDocs } from "firebase/firestore";

export default {
  setup() {
    return {
      userList: []
    };
  },
  async created() {
    const q = query(
      collection(db, "userProfile"),
      where("verified", "==", true)
    );
    const querySnapshot = await getDocs(q);
    let arr = [];
    querySnapshot.forEach(doc => {
      // doc.data() is never undefined for query doc snapshots
      let docData = doc.data();
      this.userList.unshift(docData);
    });
    console.log(this.userList)
  }
};
</script>

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Oh, I think your problem is that you didn't make userList reactive (Vue Docs). Try this:

setup() {
  return {
    userList: ref([])
  };
},

and make sure you import ref:

import { ref } from 'vue';

When you use ref's you deal with the value they contain, rather than the ref directly, so anywhere you were using this.userList, you should now use this.userList.value (except in the template: templates know how to deal with refs).

about 4 years ago · Juan Pablo Isaza Relatório

0

If You are using composition API put everything in setup function, there is no created hook here, so You can make function:

setup() {
  const userList = ref([]);
  const created = async () => {
    const q = query(
      collection(db, "userProfile"),
      where("verified", "==", true)
    );
    const querySnapshot = await getDocs(q);
    let arr = [];
    querySnapshot.forEach(doc => {
      let docData = doc.data();
      userList.value.unshift(docData);
    });
  };
  created();
  return {
    userList
  };
},
about 4 years ago · Juan Pablo Isaza Relatório

0

I think your issue might be that templates need a single root node, and your v-for makes there be multiple roots in the template. Try wrapping it in a <div>.

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