Uploading files with VueJS, axios and Laravel

喜夏-厌秋 提交于 2019-12-01 06:45:57

Oh yeah! you're missing this part. You need to define this.

axios.defaults.headers.post['Content-Type'] = 'multipart/form-data';

this my solutuion

export default {
    data (){
        return {
            attachment : { name : null,file: null }
        }
    },
    methods : {
        onFileChange(event) {
            this.attachment.file = event.target.files[0]
        },
        attachmentCreate() {
            var form = new FormData();

            form.append('name',this.attachment.name);
            form.append('file',this.attachment.file);
            this.$http.post('attachment',form).then(response=>{
               console.log("oke")
            })
        },
    }
 }
<input type="file" class="form-control" @change="onFileChange">
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!