I am receiving a GET request from my API to display all users, and I want to potentially modify the name or email of each user using a modal. However, I am facing an issue where if I have 3 users displayed, clicking on one modal button triggers all 3 modals to appear.
How can I resolve this problem?
Below is my code snippet:
<template>
<div class="container">
<div>
<h1>
<b> Users </b>
<input
type="text"
v-model="search"
class="search"
placeholder="Search User"
/>
</h1>
</div>
<div class="overlay-container">
<form>
<div class="form-group">
<div
v-for="user in filterUser"
v-bind:key="user"
class="form-control"
>
<p>
<b>{{ user.fname }} </b> {{ user.lname }}
</p>
<b-button v-b-modal.modal-1>Modify</b-button>
<b-modal id="modal-1" title="User Modification">
<p class="my-4">Please edit information</p>
</b-modal>
</div>
</div>
</form>
</div>
</div>
</template>
<script>
import axios from "axios";
import VueAxios from "vue-axios";
export default {
name: "users",
data() {
return {
search: "",
users: [],
};
},
computed: {
filterUser() {
return this.users.filter((user) => {
return user.fname.match(this.search);
});
},
},
created() {
axios
.get(`http://localhost:4000/api/users`)
.then((Response) => (this.users = Response.data.data));
},
};
</script>
I would like each user to open their own modal, instead of triggering all modals when clicking on just one button. I hope this explanation clarifies the issue!