Component display based on v-select option in Vuetify, Vue and Typescript

Salifyanji Taala
3 min readOct 10, 2020

--

In this post am going to share with you how you can display a component based on the option selected using the v-select in Vuetify, Vue and Typescript.

We are going to start with creating a v-select and bind items to items array which we are going to create in Typescript

A vuetify v-select component

After we have created our v-select component, we want to display a red button when the option red is selected and the green button when selected. So we are going to declare an array called items holding button options.

Items Array holding button names

The front end results will show like the snippet below:

v-select showing button options in the front end

Initially our Vue, Vuetify code looks like this below, we need to modify it to get our desired results.

So we need to create a function called selectButton that will help us achieve the result we are looking for. Don’t mind the console.log message in this case it is for testing purposes.

Add the event called @change that will help in changing the component dynamically and feed it with the selectButton function that has been created.

Next : Declare selected variable as a string

Feed selected variable to the V-model .

Lastly we need to add the v-if , to render if the directive’s expression returns a truthy value.

In our front end, when a Red Button Options is selected it should show the Red Button components like below

When a Green Button Options is selected it should show the Green Button components like below

This is how you change the components dynamically using Vuetify v-select component Vue and Typescript. Hopefully you find the code helpful . Happy coding.

--

--

Salifyanji Taala
Salifyanji Taala

Written by Salifyanji Taala

Philomath. Everything posted is based on my Experience and learning from others.

Responses (2)