Home > Net >  I want to add active class on the button that got clicked and remove from the another button, vice v
I want to add active class on the button that got clicked and remove from the another button, vice v

Time:02-10

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
            :
            @click="sortUp()"
          >
            Price low to Hight
          </button>
          <button
            :
            @click="sortDown()"
          >
            Price Hight to Low
          </button>

CodePudding user response:

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

<button :@click="sortUp(),setFalse(1)>Price low to Hight</button>
<button:@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;
      }
    },
  • Related