Skip to content

Instantly share code, notes, and snippets.

@ecmel
Last active January 17, 2018 19:03
Vuetify file selection button
<script>
export default {
name: 'VFileBtn',
props: {
value: {
type: File,
default: null
},
accept: {
type: String,
default: ''
},
disabled: {
type: Boolean,
default: false
}
},
methods: {
clicked() {
this.$refs.input.click()
},
changed(e) {
const file = e.target.files[0]
if (file) {
this.$emit('input', file)
}
}
}
}
</script>
<template>
<div class="file-btn">
<input
ref="input"
type="file"
:accept="accept"
:disabled="disabled"
@change="changed">
<v-btn
:disabled="disabled"
@click="clicked"><slot>Browse</slot></v-btn>
</div>
</template>
<style scoped>
.file-btn {
display: inline-block;
}
.file-btn input[type=file] {
position: absolute;
filter: alpha(opacity=0);
opacity: 0;
}
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment