Untitled
Anonymous
Plain Text
09/24/2025 10:52 PM
3.9 KB
14
Indexable
Never
<template>
<div>
<v-container fluid>
<v-row>
<v-col cols="4">
<v-text-field v-model="toAdd.employeeCode" dense outlined label="Employee Code"></v-text-field>
<v-text-field v-model="toAdd.employeeName" dense outlined label="Employee Name"></v-text-field>
<v-text-field v-model="toAdd.age" dense outlined label="Age"></v-text-field>
<v-text-field v-model="toAdd.address" dense outlined label="Address"></v-text-field>
<v-btn block color="success" @click="saveEmployee()">
{{ btnAction === 'ADD' ? 'Save' : 'Update' }}
</v-btn>
</v-col>
<v-col cols="8">
<v-simple-table dense>
<thead>
<tr>
<th>Employee Code</th>
<th>Employee Name</th>
<th>Age</th>
<th>Address</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, i) in listOfEmployee" :key="i">
<td>{{ item.employeeCode }}</td>
<td>{{ item.employeeName }}</td>
<td>{{ item.age }}</td>
<td>{{ item.address }}</td>
<td>
<v-btn color="primary" icon @click="editEmployee(item, i)">
<v-icon>mdi-pencil</v-icon>
</v-btn>
<v-btn color="error" icon @click="deleteEmployee(i)">
<v-icon>mdi-delete</v-icon>
</v-btn>
</td>
</tr>
</tbody>
</v-simple-table>
</v-col>
</v-row>
</v-container>
</div>
</template>
<script>
export default {
data() {
return {
toAdd: {},
btnAction: 'ADD',
editIndex: -1,
listOfEmployee: [
{
employeeCode: '00000',
employeeName: 'Zero',
age: 18,
address: 'Tanza'
},
{
employeeCode: '11111',
employeeName: 'One',
age: 19,
address: 'Noveleta'
},
{
employeeCode: '22222',
employeeName: 'Two',
age: 20,
address: 'Gen. Trias'
}
]
};
},
methods: {
saveEmployee() {
if (this.btnAction === 'ADD') {
this.listOfEmployee.push({ ...this.toAdd });
} else {
this.listOfEmployee.splice(this.editIndex, 1, { ...this.toAdd });
}
this.clearForm();
this.btnAction = 'ADD';
this.editIndex = -1;
},
editEmployee(item, index) {
this.toAdd = { ...item };
this.btnAction = 'UPDATE';
this.editIndex = index;
},
deleteEmployee(index) {
alert('are you sure want to delete this?')
this.listOfEmployee.splice(index, 1);
},
clearForm() {
this.toAdd = {
employeeCode: '',
employeeName: '',
age: '',
address: ''
};
}
}
};
</script>Editor is loading...
Leave a Comment