Skip to content

Instantly share code, notes, and snippets.

@ShuvoHabib
Created May 13, 2017 16:44
Show Gist options
  • Save ShuvoHabib/778387ebe72ffd59d5608ccebb476d55 to your computer and use it in GitHub Desktop.
Save ShuvoHabib/778387ebe72ffd59d5608ccebb476d55 to your computer and use it in GitHub Desktop.
Vue 2 JS: File uploader with custom events
const File = {
name: 'File',
methods: {
openFileDialogue() {
const field = this.$refs.field;
const event = new MouseEvent('click', {
view: window,
bubbles: false,
cancelable: true
});
field.dispatchEvent(event);
},
},
render(h) {
return (
<span on-click={this.openFileDialogue}>
<i className="fa fa-icon-image"/>
<input
type="file"
name="file"
ref="field"
style={{ display: 'none' }}
/>
</span>
);
}
};
export default File;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment