2017-02-28 58 views
0

我是axios的新手,所以我需要幫助。我在laravel 5.3中使用axios上傳圖像文件,但axios沒有將圖像文件傳遞到服務器。這是我的axios代碼。在laravel上使用axios上傳圖片文件5.3

formSubmit: function(){ 

     axios.post('/postdata',this.$data,) 
      .then(response => alert('Success')) 
      .catch(error => this.errors.record(error.response.data)); 

    }, 

除文件本身外,整個表單數據都被提交。

回答

0

嗯,我認爲你應該在處理ajax文件上傳時使用FormData()對象。

let formData = new FormData(); 
this.form.append(ele.target.name, files[0]) 

axios.post('/postdata', formData) 
     .then(response => alert('Success')) 
     .catch(error => this.errors.record(error.response.data));