2017-02-28 63 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));