I have a problem for removing a specific element in a list.
I have used splice who is supposed to cut the element at a certain point but it always remove the last element.
<template>
<div>
<v-row>
<v-col>
<h3>Steam</h3>
<v-btn class="mx-2" fab dark color="purple" @click="addCardSteam">
<v-icon dark>mdi-plus</v-icon>
</v-btn>
</v-col>
<v-col>
<h3>Map 2D et 3D</h3>
<v-btn class="mx-2" fab dark color="cyan" @click="addCardMaps">
<v-icon dark>mdi-plus</v-icon>
</v-btn>
</v-col>
<v-col>
<h3>Youtube</h3>
<v-btn class="mx-2" fab dark color="red" @click="addCardYT">
<v-icon dark>mdi-plus</v-icon>
</v-btn>
</v-col>
</v-row>
<v-row>
<v-col>
<YTCard v-for="(card, index) in Youtube"
v-bind:key="index"
v-model="card.deleted"
@input="UpdateYT"></YTCard>
</v-col>
</v-row>
</div>
</template>
<script>
import YTCard from './YoutubeCard'
export default {
data: () => ({
Steam: [],
Maps: [],
Youtube: [],
YT: 0
}),
methods: {
UpdateYT: function () {
console.log('Youtube => ', this.Youtube)
this.Youtube = this.Youtube.filter(yt => !yt.deleted)
},
addCardYT: function (num) {
this.YT = this.YT + 1
this.Youtube.push({deleted: false, num: this.YT})
},
addCardMaps: function () {
this.Maps.push({deleted: false})
},
addCardSteam: function () {
this.Steam.push({deleted: false})
}
},
components: {
YTCard
}
}
</script>
<style scoped>
</style>
I have tried different ways but it always destroys the last element.
Does someone has an explanation or an idea.
I have edited the Question i hope it make it clearier.
i--you a re checking against the length of the array which should change with a splice?for (let i = 0; i < this.Youtube.length; i++) { console.log('i = ', i) console.log(this.Youtube[i].deleted) if (this.Youtube[i].deleted === true) { console.log('i = ', i) this.Youtube.splice(i, 1) } }