I have three buttons, I want to make it so that I can select one of these buttons, and then when I click on the button called Save to local storage, the value of the selected button is saved in local storage, I use the object that stores the button text and value like
{ btnText: "Green", value: "green-value" }
Here is my complete code
<template>
<div>
<div>
<div v-for="(i, index) in buttonsGroup" :key="index">
<button
:class="{
EthnicityActive:
i === EthnicityActive && 'EthnicityActive-' + index,
}"
v-on:click="EthnicityActive = i"
>
{{ i.btnText }}
</button>
</div>
</div>
<div class="save">
<button @click="save">Save to local storage</button>
</div>
</div>
</template>
<script>
export default {
data() {
return {
buttonsGroup: [
{ btnText: "Green", value: "green-value" },
{ btnText: "Blue", value: "blue-value" },
{ btnText: "Orange", value: "orange-value" },
],
Save: null,
EthnicityActive: "",
};
},
methods: {
save() {},
},
};
</script>
I think everything is clear here, I created an object, then I used v-for, I got buttons, there is also a Save To Local Storage button, in order to save it to local storage after I selected one of these three buttons
You can also see the given code in codesandbox