Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

I want to add active class on the button that got clicked and remove from the another button, vice versa in vue js

I want to add an active class while the first button is clicked and remove the active class if it’s there in the second button same condition for the second button how can I achieve it.

<button
            :class="{ active: isActiveAc, sortas: true }"
            @click="sortUp()"
          >
            Price low to Hight
          </button>
          <button
            :class="{ active: isActiveDc, sortas: true }"
            @click="sortDown()"
          >
            Price Hight to Low
          </button>

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I would like to give you a basic idea which might help you.

<button :class="{ active: isActiveAc, sortas: true }"@click="sortUp(),setFalse(1)>Price low to Hight</button>
<button:class="{ active: isActiveDc, sortas: true }"@click="sortDown(),setFalse(1)">Price Hight to Low</button>

and add the following function in a method.

setFalse(c) {
      if (c == 1) {
        this.isActiveAc = true;
        this.isActiveDc = !this.isActiveAc;
      } else if (c == 2) {
        this.isActiveDc = true;
        this.isActiveAc = !this.isActiveDc;
      }
    },
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading