I'm a newbie and I fetched some data from firebase and after being able to display, add and delete them successfully. I also want to edit them and update them to firebase again.
So I bind the post I wish to edit to an input wth v-model, called an editPost function on the edit button and I also passed in the index but the issue I'm having is that if I clicked the edit button on one of the posts it is also firing the other edit buttons
This is my template:
<div v-for="(post, i) in posts" :key="i">
<h3>By: {{ post.name }}</h3>
<p>
{{ post.post }}
</p>
<p>{{ post.date }}</p>
<button @click="deletePost(i)">delete</button>
<button v-if="editMode" @click="editPost(i)">Edit</button>
<input type="text" v-if="!editMode" v-model="post.post">
<button v-if="!editMode" @click="savePost">Save</button>
<button v-if="!editMode" @click="cancleEditMode">Cancle</button>
</div>
This is where I called the editPost function:
const editMode = ref(true)
const postItem = ref("")
const editPost = (i) => {
editMode.value = false
postItem.value = posts.value.find((post) => post.i === i)
console.log(i)
}