0

I want to create a button which will change the color of md-card after click. I'm not certain how I should do this. I have idea that here should be variable which is changing after click from false to true and then some function execution but don't know what should be inside.

<template>
  <div>
    <md-card class="md-primary" md-with-hover >
      <md-ripple>
        <md-card-header>
          <div class="md-title" >color</div>
        </md-card-header>

        <md-card-actions md-alignment="space-between">
          <md-button v-on:click="available = !available">Action</md-button>
        </md-card-actions>
      </md-ripple>
    </md-card>
  </div>
</template>


<script>
  export default {
    name: 'FirstRouteChild',
    data: {
        available: true,
        },
    computed: {
    }
  }
</script>


<style lang="scss" scoped>
  @import "../../node_modules/vue-material/src/theme/engine";
  @import "../../node_modules/vue-material/src/base/theme";*/
  @import "../../node_modules/vue-material/src/components/MdCard/theme";

  @include md-register-theme("default", (
    primary: md-get-palette-color(green, A200), // The primary color of your application
    accent: md-get-palette-color(red, A200) // The accent or secondary color
  ));

  .md-card {
    width: 320px;
    margin: 4px;
    display: inline-block;
    vertical-align: top;
  }
</style>
Craig van Tonder
  • 7,497
  • 18
  • 64
  • 109
Beorn
  • 417
  • 1
  • 5
  • 13

1 Answers1

0

You can bind a class to a boolean with the following syntax:

v-bind:class="{ availableClassName: available }"

In your example this becomes:

<div>
  <md-card v-bind:class="{ availableClassName: available }" class="md-primary" md-with-hover >
    <md-ripple>
      <md-card-header>
        <div class="md-title" >color</div>
      </md-card-header>
      <md-card-actions md-alignment="space-between">
        <md-button v-on:click="available = !available">Action</md-button>
      </md-card-actions>
    </md-ripple>
  </md-card>
</div>

See the documentation for more details: https://v2.vuejs.org/v2/guide/class-and-style.html

tony19
  • 125,647
  • 18
  • 229
  • 307