vue 上传图片



methods: {
        upload: function(e) {
            e.preventDefault();
            //var files = this.$refs.files;
             var files = e.target.files;
            var data = new FormData();
            data.append('avatar', files[0]);
         
            this.$http.post('/avatars/upload', data, function (data, status, request) {
                  //handling
            }).error(function (data, status, request) {
                 //handling
            });
        }
姓名
性別
new Vue({ el: '#main', methods: { submit: function(event) { // FormData支援把 Form 元素丟進去 var formData = new FormData(event.target) this.$http.post('/path/to', formData, function (data, status, request) { // Success }).error(function (data, status, request) { // Error }); } } })

前端处理图片压缩
https://github.com/think2011/localResizeIMG
js image转base64编码



 
     
    Document


    



你可能感兴趣的:(vue 上传图片)