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

133
Vistas
Input addEventListener doesn't work on change

please help me out in this. I am trying to save profile picture but the input.addeventlistener doesn't files on change. I am using vue with rails

This is the mount hook in when in a vue component where I want to trigger the eventlistener.

    mounted() {
    debugger
    this.previewUrl = this.placeholder;
    
    const input = this.$refs.inputSlot.querySelector('input[type="file"]')
    if (input) {
      input.addEventListener('change', event => {
        if(input.files[0]){
        const fakeFilePath  = event.currentTarget.value
        if (input.files[0].size > this.sizeLimit) {
          alert(this.$t('error.file_size', { max_size: this.maxSize }));
          input.value = '';
        } else {
          this.fileName = input.files[0].name

          if (this.preview == 'image') {
            const reader = new FileReader();
            reader.onload = event => {
              this.selectedFile = this.oldImage = this.previewUrl;
              this.previewUrl =  event.target.result;
              this.choosenFile = fakeFilePath;
            };
            reader.readAsDataURL(input.files[0]);
          }
        }
      }
      })
    }
  }

This is the input field

<input accept="image/jpeg,image/png,.jpeg" type="file" name="user[profile_picture]" id="user_profile_picture">

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

0

You can simply add @change="save" attribute to your input and after file change save method will gets triggered

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