@submit.prevent="createArticle"
<form method="" action="">
, therefore, No need @click
in button. <form @submit.prevent="createArticle()">
<input name="title" v-model="article.title">
<input name="body" v-model="article.body">
<button>Add </button>
</form>
methods:{
createArticle(){
fetch('api/articles', {
method: 'POST',
body: JSON.stringify(this.article),
headers:{
'content-type': 'application/json'
}
}).then(res => res.json())
.then(data => {
alert('article created');
this.article.title = ''; //to clear the input
this.article.body = '';
this.fetchArticles //to get the updated articles after creation
}).catch(err => console.log(err));
}
}