Created
November 2, 2016 03:35
-
-
Save rydurham/0d2ea73e145ed6b92eb272f6fab032d9 to your computer and use it in GitHub Desktop.
Vuejs image upload
This file contains 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
<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