Last active
January 17, 2018 19:03
-
-
Save ecmel/3e4dc79a6815fed2ce6a9a99697bd0dd to your computer and use it in GitHub Desktop.
Vuetify file selection button
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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