5

I am trying to change the class to apply on a Vuetify.js component based on whether there is a mouse hover or not:

<v-card
    class="mx-auto"
    width="344"
  >
    <v-hover>
    <v-card-title
      slot-scope="hover"
      :class="`${hover? class1: class2}`">
      <div>
        <span class="headline">Hover</span>              
        </div>
      </div>

    </v-card-title>
    </v-hover>
  </v-card>

The CSS classes simply set the background-color property:

.class1 {
  background-color:red;
}

.class2 {
  background-color:blue;
}

For some reason, this is not working. What am I missing?

Codepen.

2
  • 2
    Did you see the error in the console? Commented Nov 9, 2018 at 10:23
  • I was trying to provide an MCVE , but you are right, thank you :) Commented Nov 9, 2018 at 10:53

1 Answer 1

7

You miss quotes in your prop class binding and curly braces in your slot-scope prop.

It should be defined like this :

slot-scope="{ hover }"
:class="`${hover? 'class1': 'class2'}`">

Working CodePen

Vuetify Hover Doc

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.