1

Can some one tell me what im do wong Im try to use ternary operator in v-slot scope

Here is my code

<template :v-slot="category.children.length ? `activator` : `default`">
    <v-list-item-avatar>
       <v-img :src="`/uploads/image/category/` + category.image"></v-img>
    </v-list-item-avatar>
    <v-list-item-content>
       <v-list-item-title v-text="category.name"></v-list-item-title>
    </v-list-item-content>
</template>

If anyone knows a solution to this problem, I will be very grateful

4
  • nothing wrong with your ternary , what errors are you getting does both v-slot="activator" and v-slot="default" work? you may need a v-if="category.children" somewhere if the model is not predefined as an array Commented Aug 31, 2020 at 11:32
  • I don't see anything wrong here. Unless you tell us what you're trying to achieve? Commented Aug 31, 2020 at 11:33
  • Im just guessing, you get property of undefined error? Commented Aug 31, 2020 at 11:44
  • In this situation whem im using ternary operator the page not a render But when im using simple v-if v-else everything ok Commented Aug 31, 2020 at 11:57

1 Answer 1

3

In order to use dynamic slot names, you need to use this syntax as specified in the docs:

<base-layout>
  <template v-slot:[dynamicSlotName]>
    ...
  </template>
</base-layout>

For example you can add a computed property like so:

computed: {
  dynamicSlotName() {
    return this.category.children.length ? "activator" : "default";
  }
}
Sign up to request clarification or add additional context in comments.

Comments

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.