I have tried to use file system (fs module) but, not getting that how to use that FS module. could anyone explain with proper example.
I was doing an example in vue js.
- Create component
- Added json file
- Pass records as props on component
- listen that props on another component
- and render student list and perform remove record
Now next i want to Pass updated list using emit & update the JSON as well
This code is working properly just i want to update local json file after delete record.
StudentRegistration.vue
<template>
<div class="container">
<div class="row">
<template v-if="students.length">
<!-- {{student.length}} -->
<studentCard class="student__parent" v-for="student in students" :key="student.id" :student="student" @studentRemoveId="studentRemoveId"/>
</template>
<template v-else>
<div class="not__available">
Data not available
</div>
</template>
</div>
</div>
</template>
<script>
import studentCard from './studentCard.vue'
import studentData from '../data/StudentData.json'
export default {
name: 'StudentRegi',
components:{
studentCard
},
data() {
return {
students: studentData,
}
},
methods: {
studentRemoveId(studid){
this.students = this.students.filter( item => {
console.log('hey there ::=> ', item);
return item.id !== studid.id
});
}
},
}
</script>
studentCard.vue
<template>
<div>
<span class="student__remove" @click="removeStudent(student)">X</span>
<div class="student__inner">
<div class="student__image">
<img :src="student.avatar" alt="">
</div>
<div class="student__name student-detail">
<div>Name</div>
<div>{{student.fname}} {{student.lname}}</div>
</div>
<div class="student__age student-detail">
<div>Age</div>
<div>{{student.age}}</div>
</div>
<div class="studet_email student-detail">
<div>Email</div>
<div>{{student.email}}</div>
</div>
<div class="student__phone student-detail">
<div>Phone</div>
<div>{{student.phone}}</div>
</div>
</div>
</div>
</template>
<script>
export default {
name:'StudentCard',
props:['student'],
methods: {
removeStudent(studid){
this.$emit('studentRemoveId', studid);
}
},
}
</script>
data.json
[
{
"id": 1,
"fname": "Atul",
"lname": "Bhavsar",
"age": "10 Years",
"email": "[email protected]",
"phone": "9685958698",
"avatar": "https://i.postimg.cc/d3ykpLs8/stud1.jpg"
},
{
"id": 7,
"fname": "Foram",
"lname": "Dobariya",
"age": "20 Years",
"email": "[email protected]",
"phone": "9856985698",
"avatar": "https://i.postimg.cc/QtWp5XBn/stud7.jpg"
},
]
