I'm building a website with VueJS and AdonisJS, and I'm setting up a possibility to publish or unpublish an article just by setting the draft attribute to true or false.
This attribute edition is possible from the index, where all the articles can be seen. I made a table where there's an action button that would toggle the attribute, which would send an HTTP POST request to Adonis with the ID.
My concern is for what comes after: I don't believe that replacing the whole array is the good option, but what should I do instead? I tried the following:
handlePublish (id) {
this.$axios.post('/post/publish', {id: id}, {
headers: {
'Authorization': `Bearer [some token]`
}})
.then(response => {
console.log(response)
let toDelete = ''
this.posts.map((post, index) => {
if (post.id === id) {
toDelete = index
}
})
this.posts.splice(toDelete, 1)
this.posts.push(response.data)
})
.catch(e => console.log(e.response))
}
But somehow nothing gets update, excepted in the database.
Thank you in advance
successyou simply need to find the post which you have gotten from your response in your posts array and update itsdraftproperty.