N
N
Nubbb2021-02-10 15:30:07
Vue.js
Nubbb, 2021-02-10 15:30:07

How to trigger input change event on button click in Vue?

there is an input

<input
          id="form-avatar"
          type="file"
          ref="uploadAvatar"
          autocomplete="off"
          accept="image/png,image/jpeg,image/bmp,image/tiff"
          @change="onFileChange"
        />

and button

<button
              type="button"
              class="btn btn-upload"
              @click.prevent="changeUpload"
            >
              Загрузить
            </button>


how to trigger input change event on button click? Or is there another way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Tigran Abrahamyan, 2021-02-10
@Nubbb

<button
  type="button"
  class="btn btn-upload"
  @click.prevent="$refs.uploadAvatar.click()"
>
  Загрузить
</button>

N
no_one_safe, 2021-02-10
@no_one_safe

You have vue, in the changeUpload method you call the onFileChange method.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question