-1👍
As noted in your comments above, this is an issue with authorization. I’ll leave my old answer here for posterity, but including the status code from the start of the question would be good next time.
I believe your ‘this’ context is invalid when used inside the callback like that. Try something like this (edit) just realized you wanted the addPosts section:
addPost(){
let vm = this;
axios.post('http://{mylink}/home/addPost', {
content:this.content
})
.then(function(response){
console.log('Data updated');
if (response.status == 200) {
alert('Your post has been updated');
vm.posts=reponse.data;
}
})
.catch(function(error){
console.log(error.response);
});
}
-1👍
I see many problems to your code but if the problem is only in addPost (you said that there is the problem) method then replace it with the follow:
addPost(){
axios.post('http://{mylink}/home/addPost', {
content:this.content
})
.then(response => {
console.log(response.data);
if (response.status == 200) {
alert('Your post has been updated');
this.posts = reponse.data;
}
})
.catch(error =>{
console.log(error.response);
});
}
also if you replace your method with the method that i posted you will be able to see what response you get from backend since i console logged it.Then you will see if you get a desired response
- [Vuejs]-Momentjs shows isValid true and console logs correct date and flashed correct .fromNow() but quickly changes to invalid date
- [Vuejs]-Can't generate data from object list Vuejs
Source:stackexchange.com