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

157
Visualizações
Display multiple files name VueJS error push is not a function

I wan't to display multiple files name in my template i'm do that:

<div v-for="(image, index) in imagesReturn" :key="index">
          <span>{{ image.name }}</span>
        </div>
        <div>
          <generic-input
            v-model="imagesReturn"
            type="file"
            multiple
            @change="addFiles"
          >
            add files
          </generic-input>
       </div>

<script>
data() {
return{
 imagesReturn: [];
 }
}
methods: {
  addFiles(e) {
      let selectedFiles = e.target.files;
      for (let img of selectedFiles) {
        this.imagesReturn.push(img.name);
      }
    }
}
</script>

Iwant to display files name in array imagesReturn but i have error when i push inside array error this.imagesReturn.push is not a function i don't know why and i can not display files name in my template. Please thank you.

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

The js part seems fine to me. I guess the problem goes from the generic-input component.

Typically, when the error something.push is not a function occurred, it always means something is not an Array.

Since imagesReturn is two-way binding using v-model, it is possible that the generic-input component alters imagesReturn from [] to ''(empty string) or null after mounted.

So I suggest you console.log(this.imagesReturn) inside addFiles() to see when the value changes (or watch imagesReturn).

I don't know if the generic-input component belongs to a UI framework or is created by yourself. If belongs to a UI framework, you need to read the documentation carefully about @change="function(params)" event, especially its params. If it's wrote by yourself, you need to check what value it will pass in the component when emit('change', value).

over 4 years ago · Santiago Trujillo 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