I want to use a delete function to remove a specific object in an array.
I tried the splice()
method but it removes just the first array no matter which objects I clicked on
Here is the code for object with a v-for method
<li v-for=" skill in skills" :key="skill.id">
{{skill.skill}}
<i class="fa fa-minus-circle v-on:click="remove(skill)"></i>
</li>
here is the Skill.vue
<script>
import uuid from "uuid";
export default {
name: "Skills",
data() {
return {
skill: "",
skills: [
{ id: uuid.v4(), skill: "Vue.js" },
{
id: uuid.v4(),
skill: "Javascript"
},
{
id: uuid.v4(),
skill: "Rails"
}
]
};
},
methods: {
addSkill() {
this.$validator.validateAll().then(result => {
if (result) {
this.skills.push({ skill: this.skill, id: uuid.v4() });
this.skill = "";
}
});
},
remove(id) {
this.skills.splice(id, 1);
}
}
};
How can I construct the method
remove(id) {
this.skills.splice(id, 1);
}
to delete the specific object?