2👍
✅
this
does not point to the vue instance in your Promise’s success callback
Use a arrow function instead. Arrow function binds the value of this
lexically
const app = new Vue({
el: '#app',
data: {
content: '',
posts: []
},
......
.then( (response) => {
if(response.status===200) {
//reload posts
app.posts = response.data;
this.content = '';
}
})
Or create a local variable pointing the correct vue instance and use it to access your data property like this:
methods:{
addPost(){
var vm = this;
//.....axios post
.then( (response) => {
if(response.status===200) {
//reload posts
app.posts = response.data;
vm.content = '';
}
})
}
}
Source:stackexchange.com