JSFiddle - React, Tailwind, and code Playground
HTML
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<!-- Font-awesome -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<title>Example</title>
</head>
<body>
<div class="container">
<div class="row">
<div id="app" class="col-12 p-3">
<student-component></student-component>
</div>
</div>
</div>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
</body>
</html>
JavaScript
Vue.component('student-component', {
data: function() {
return {
counter: 0,
students: [],
currentStudent: {},
currentIndex: -1
};
},
methods: {
add: function() {
this.students.push({
key: this.counter++,
name: '',
email: '',
phone: '',
address: ''
});
},
remove: function(index) {
this.students.splice(index, 1);
},
edit: function(index) {
this.currentStudent = this.students[index];
this.currentIndex = index;
$('#student-modal').modal('show');
},
save: function(data, index) {
Vue.set(this.students, index, JSON.parse(JSON.stringify(data)));
$('#student-modal').modal('hide');
}
},
mounted: function() {
$('#student-modal').on('hidden.bs.modal', () => {
this.currentStudent = {};
this.currentIndex = -1;
});
},
template: `
<div class="table-responsive">
<p><button type="button" class="btn btn-sm btn-primary" @click="add">Add</button></p>
<table class="table table-sm table-bordered">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Email</th>
<th scope="col">Phone</th>
<th scope="col">Address</th>
<th scope="col">Edit</th>
<th scope="col">Remove</th>
</tr>
</thead>
<tbody>
<tr v-for="(student, index) in students" :key="student.key">
<th scope="row">{{ index + 1 }}</th>
<td>{{ student.name }}</td>
<td>{{ student.email }}</td>
<td>{{ student.phone }}</td>
<td>{{ student.address }}</td>
<td class="text-center">
<button type="button" class="btn btn-sm btn-outline-dark fa fa-edit" @click="edit(index)"></button>
</td>
<td class="text-center">
<button type="button" class="btn btn-sm...