With v-for I display elements to the screen then using classes from vue js (:class) I present the ability to select certain elements by clicking on them
The problem is that my plans have changed and now I need to make sure that the user can select as many elements as he wants, that is, at the moment you can select only one element when clicking on another element, the active class from the previous element is disabled now I need to select as many elements How many do you need.
Here is the given code in codesandbox
<template>
<div>
<ul class="times-slot">
<li
v-for="(item, index) in TimeToChoose"
:key="index"
:class="{ 'selected-time': item === selectedTime }"
v-on:click="selectedTime = item"
>
{{ item }}
</li>
</ul>
</div>
</template>
<script>
let ts = require("time-slots-generator");
export default {
name: "HelloWorld",
data() {
return {
TimeToChoose: ts.getTimeSlots([], true, "half"),
selectedTime: "",
};
},
};
</script>
<style scoped>
.selected-time {
background: #CC003D;
border: 1px solid #FFFFFF;
color: white;
}
.times-slot {
display: flex;
align-items: center;
margin: 0;
padding: 0;
}
.times-slot li {
min-width: 70px;
border-radius: 7px;
border: #ffffff;
padding: 4px 0 4px 0;
}
.times-slot li:hover {
cursor: pointer;
}
li {
list-style-type: none;
}
</style>