I am trying to create a user feedback form where users can rate the quality of the food item they ordered. I have an array foodItems which render the food list and i have certain reactions set up for the food items. I am trying to add a method so that user can provide the feedback but user can set up only one reaction at a time. So for instance for Pizza they can be satisfied or dissatisfied and the selected reaction should be highlighted and so on but i am not sure how i can do it.
Check out this sample codepen.
Check out this working example:-
new Vue({
el: "#app",
data() {
return {
reaction: false,
selectedReaction: "",
foodItems: [{
name: "Pizza",
value: "pizza"
},
{
name: "Pasta",
value: "pasta"
}
]
};
},
methods: {
setReaction() {
this.reaction = !this.reaction;
}
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.js"></script>
<link rel="stylesheet" href='https://fonts.googleapis.com/css?family=Roboto:300,400,500,700|Material+Icons'>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/vuetify.min.css" rel="stylesheet" />
<div id="app">
<v-app id="inspire">
<v-container>
<v-layout row wrap justify-center>
<v-flex xs6 v-for="(food,index) in foodItems" :key="index">
<h1>{{ food.name }}</h1>
<v-icon large left :color="reaction ? 'primary' : ''" @click="setReaction">sentiment_dissatisfied</v-icon>
<v-icon large :color="reaction ? 'primary' : ''" @click="setReaction">sentiment_very_satisfied</v-icon>
</v-flex>
</v-layout>
</v-container>
</v-app>
</div>
So basically i am trying to add the functionality for the users to rate the food. Any help will be appreciated. Thank you so much.