[Vuejs]-How to upload image/file from Vue js to Laravel7 using axios

0👍

You have to use javascript’s FormData API to post file to your Laravel app using vue.
Modify the code in your view component as follows

data(){
    return{
        id : '',
        file: '',
        address : '',
        N_Phone : '',
    }
},
methods:{
    RemplirInfo(e){
        e.preventDefault();

        var form = new FormData();
        form.set('address',this.address);
        form.set('N_Phone',this.N_Phone);
        form.set('file',this.file);

        axios.put('http://127.0.0.1:8000/api/RemplirInfo/'+this.id , form)
        .then(response=> console.log(response))
        .catch(error => console.log(error));
    },
    imgChange(e){
        this.file = e.target.files[0];
    }
},

Leave a comment