Vuetify Change color of v-chip on click

In this post, we will explore how to change the color of Vuetify's v-chip component when it is clicked. Vuetify is a popular UI framework for Vue.js, and it provides a wide range of components to build beautiful and responsive web applications.

The v-chip component is often used to display small pieces of information or trigger actions. By default, v-chips come with predefined colors. However, we want to make them dynamic by changing their colors on click.

Profile Photo

Abhishek Yadav (SD) SDE of FAI

Feedback

written
Profile Photo

Anil Kumar (Expert) Coding Expert of FAI

Feeback

reviewed
Profile Photo
Nov 02, 2023 04:11 AM Last Updated
updated

Here is the code snippet that demonstrates how to achieve this behavior:

In this code, we have a v-container that holds five v-chip elements. Each v-chip is bound to a color property that is determined by the value of a data variable, like isClicked1. The color changes from the primary color to the secondary color (and other combinations) when the v-chip is clicked. The @click event handler toggles the value of the corresponding data variable

Copied to Clipboard
Run

Here is the JavaScript part that sets up the Vue.js instance:

Changing Vuetify v-chip Color on Click

Copied to Clipboard

This code initializes a new Vue instance with a data section that defines the initial values of our click variables.

Output of Vuetify Change Color Of V-Chip On Click 

Pasted Image

In conclusion, this post demonstrates how to change the color of Vuetify's v-chip component on click using Vue.js. This interactivity enhances the user experience and allows you to create engaging web applications with Vuetify. Feel free to modify the colors and icons to suit your project's needs and styling preferences.

Ad