I'll post the code, I can't store the data in the tweets array, where am I wrong? i am using vue and laravel
<script>
export default {
mounted() {
this.recupera_post()
},
data(){
return{
tweets:[]
}
},
methods:{
async recupera_post(){
await axios.get('api/schedulepost')
.then(function(response){
console.log(response.data)
app.tweets=response.data
})
}
}
}
</script>
CodePudding user response:
you just need to write this.tweets
also you need to change your callback function to arrow function to allow you to access your state like this
async recupera_post(){
await axios.get('api/schedulepost')
.then((response) => {
console.log(response.data)
this.tweets = response.data
})
}
}