MuaathAlhaddad
4/1/2020 - 11:10 AM

delete - fetch API

FACTS

HTML

<div v-for="article in articles" :key="article.id">
   <button @click="deleteArticle(article.id)">Delete</button>
 </div>

JS

methods: {
  deleteArticle(id){
    fetch(`api/articles/${id}`,{
      method: 'DELETE'
    })
    .then(res => res.json())
    .then(data =>{
       alert('article deleted');
       this.fetchArticles();  // to get the updated resouces after deletion  
    })
    .catch(err => console.log(err));
  }
}