1

In creating a menu using a list within a v-navigation-drawer, I will loop through a set of items and sub-items with 3 properties amongst others: title (string), location (v-router destination) and clickable (boolean). I'm working off the code here and would like some items to be actual links and others simply open up further menu options and not be clickable.

Code portion is:

 <v-list-item
    v-for="subItem in item.items"
    :key="subItem.title"
    @click=""
  >
     <v-list-item-content>
            <v-list-item-title v-text="subItem.title"></v-list-item-title>
     </v-list-item-content>
 </v-list-item>

My question: how do I get the

 @click="subItem.location" 

only on

 v-if:subItem.clickable

1 Answer 1

2

You can add conditions onto the click handler as below.

<v-list-item
    v-for="subItem in item.items"
    :key="subItem.title"
    @click="subItem.clickable ? handleByFunction(subItem.location):null"
  >
     <v-list-item-content>
            <v-list-item-title v-text="subItem.title"></v-list-item-title>
     </v-list-item-content>
 </v-list-item>
methods{
  handleByFunction(v){
    console.log(v) 
 }
}
Sign up to request clarification or add additional context in comments.

1 Comment

Very nice. You could make that expression a little shorter with subItem.clickable && handleByFunction(subItem.location)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.