0

I want to trigger a hidden v-input-file by clicking a v-btn. I can do it with the regular input file, but I prefer to use v-input-file. Here is what I have done so far but it is not working.

<v-card-text class="pt-6" style="position: relative;">
    <v-btn
        absolute
        color="orange"
        class="white--text"
         fab
         small
         right
         top
         @click="$refs.avatarInput.$el.click($event)"
      >
         <v-icon>mdi-camera</v-icon>
      </v-btn>
      <v-file-input
         v-show="true"
         ref="avatarInput"
         accept="image/png, image/jpeg, image/bmp"
         placeholder="Pick an avatar"
         prepend-icon="mdi-camera"
         label="Avatar"
      ></v-file-input>
   </v-card-text>
livreson ltc
  • 661
  • 6
  • 19

1 Answers1

0

An input[type="file"] can't be fired this way due to security reasons.

Check this answer for more details https://stackoverflow.com/a/29873845/553073

Here are some options:

  1. Instead of a v-btn, use a label with for="idOfFileInput", make it looks like a button if you like. Click on the label will trigger the file input.

  2. Set z-index and opacity=0 on the file input and place it right on top of your button, so when user clicks the button the file input get clicked instead.

lastr2d2
  • 3,349
  • 1
  • 19
  • 33