Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to highlight selected item in the Vuetify menu?

I have a menu in the sidebar (using vue-router):

<v-list>
    <v-list-tile
        value="true"
        v-for="(item, i) in menu"
        :key="i"
        :to="item.path"
    >
        {{item.name}}
    </v-list-tile>
</v-list>

and it works just fine, however I don't see anything in the Vuetify docs about highlighting the selected menu item. Any help is appreciated!

UPDATE: it turns out I am not very bright. setting value="true" property ensures all elements are always active, removing that resulted in proper function. duh!

like image 797
ierdna Avatar asked Aug 31 '18 22:08

ierdna


People also ask

How do you customize Vuetify?

By default, Vuetify has a standard theme applied for all components. This can be easily changed. Simply pass a theme property to the Vuetify constructor. You can choose to modify all or only some of the theme properties, with the remaining inheriting from the default.

What is V slot activator?

Details on the activator slotVMenu allows users to specify a slotted template named activator , containing component(s) that activate/open the menu upon certain events (e.g., click ).

How do I use Vue select?

Use Vue In Our Template We can add vue-select in our component like this. < v-select : options ="fruits" ></ v-select > : This how we add Vue-select in our component, there is v-bind or : in this component, options is props we pass to component vue-select. This is the provision of the vue-select library.

Can you use Vuetify without Vue?

No, you can't run Vuetify without Vue. The reason is pretty simple, most of Vuetify is built with vue and most of those components require their script to run, so everything that's not entirely css based will not work.


1 Answers

Vuetify will by default highlight the active link element by matching against the current route.

CodeSandbox example.

However, if need be, you can control this behavior as shown in the API documents for v-list-tile and the active-class property. You can manually match the current route to the list item using something similar to:

<v-list-tile 
    v-for="(item, i) in menu"
    :key="i"
    :to="item.path" 
    active-class="highlighted"
    :class="item.path === $route.path ? 'highlighted' : ''"
>
    {{item.name}}
</v-list-tile>

See also the linkActiveClass in the Vue Router docs.

like image 191
Brian Lee Avatar answered Sep 21 '22 13:09

Brian Lee