Skip to content

Instantly share code, notes, and snippets.

@rydurham
Created November 2, 2016 03:35
Show Gist options
  • Save rydurham/0d2ea73e145ed6b92eb272f6fab032d9 to your computer and use it in GitHub Desktop.
Save rydurham/0d2ea73e145ed6b92eb272f6fab032d9 to your computer and use it in GitHub Desktop.
Vuejs image upload
<input v-el="avatar" type="file" name="avatar" id="avatar" v-on="change:upload">
methods: {
upload: function(e) {
e.preventDefault();
var files = this.$$.avatar.files;
var data = new FormData();
// for single file
data.append('avatar', files[0]);
// Or for multiple files you can also do
// _.each(files, function(v, k){
// data.append('avatars['+k+']', v);
// });
this.$http.post('/avatars/upload', data, function (data, status, request) {
//handling
}).error(function (data, status, request) {
//handling
});
}
// via @TeroBlaZe - https://github.com/vuejs/Discussion/issues/24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment