2

i'm working on a Vue.js app , this is my data :

data() {
  return {
    formAddNew: {
        cover: "",
        title: "",
        date: "",
        content: "",
        author: "",
        attachement: "",
    },
  }
}

I want to update cover after an axios request this how it looks :

          axios.post('/upload.php',
                formData,
                {
                    headers: {'Content-Type': 'multipart/form-data'}
                }
            ).then(function(data){
                this.formAddNew.cover = data.data;
            })
            .catch(function(){
                console.log('Error!')
            }); 

But it doesn't work i don't know why , please help me fix it .

1 Answer 1

3

Try to use (data)=> instead function(data) to get access to this in the callback context :

 ).then((data)=>{
               this.formAddNew.cover = data.data;
            })
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.