Created
May 13, 2017 16:44
-
-
Save ShuvoHabib/778387ebe72ffd59d5608ccebb476d55 to your computer and use it in GitHub Desktop.
Vue 2 JS: File uploader with custom events
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
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