In a q-btn-toggle, how do I have different colored buttons for each option?
- User
In a q-btn-toggle, how do I have different colored buttons for each option?
- Assistant
To have different colored buttons for each option in a
q-btn-toggle, you can achieve it by using the:classbinding to dynamically apply CSS classes based on the selected option. Each option can have a different CSS class that defines the desired background color.Here's an example where different colored buttons are assigned for each option in a
q-btn-toggleusingQuasar(a popular Vue.js UI library):<template> <q-btn-toggle v-model="selectedOption" color="primary" toggle-color="accent"> <q-btn v-for="(option, index) in options" :key="index" :label="option.label" :value="option.value" :class="option.class" class="text-white" /> </q-btn-toggle> </template> <script> export default { data() { return { selectedOption: 'option1', options: [ { label: 'Option 1', value: 'option1', class: 'bg-red-9' }, { label: 'Option 2', value: 'option2', class: 'bg-blue-9' }, { label: 'Option 3', value: 'option3', class: 'bg-green-9' }, ], }; }, }; </script> <style> .bg-red-9 { background-color: #ff6464; } /* Red button */ .bg-blue-9 { background-color: #64a1ff; } /* Blue button */ .bg-green-9 { background-color: #64ff64; } /* Green button */ </style>