0

I am trying to hide and show a font awesome 5 icon on click. The value changes behind the scene but the icon isn't being changed. I have tried the other class bindings that vue js has to offer but it produced the same result.


<template>
    ....
    <a href="#" class="social-button" @click.prevent="showAttribute(index)" rel="tooltip" data-color-class="primary" data-animate="animated fadeIn" data-original-title="" data-toggle="tooltip" data-placement="bottom">
        <i class="fa fa-eye" v-if="category.attributes[index].show"></i>
        <i class="fa fa-eye-slash" v-else></i>
   </a>
   ....
</template>

<script>
    export default {
        ...
        showAttribute(index){
            this.category.attributes[index].show = !this.category.attributes[index].show;
        },
        ...
    }
</script>
user2538755
  • 314
  • 1
  • 6
  • 21

1 Answers1

0

try with this v-if="!category.attributes[index].show" instead fo v-else

 <template>
        ....
        <a href="#" class="social-button" @click.prevent="showAttribute(index)" rel="tooltip" data-color-class="primary" data-animate="animated fadeIn" data-original-title="" data-toggle="tooltip" data-placement="bottom">
            <i class="fa fa-eye" v-if="category.attributes[index].show"></i>
            <i class="fa fa-eye-slash" v-if="!category.attributes[index].show"></i>
       </a>
       ....
    </template>

    <script>
        export default {
            ...
            showAttribute(index){
                this.category.attributes[index].show = !this.category.attributes[index].show;
            },
            ...
        }
    </script>

onPage load if you don't get the value or if you get the value null. then, you need to set the default value in the data()

here is the working example, https://codepen.io/anon/pen/rvqYgz

Sanjay V
  • 59
  • 1
  • 10