0

I am looking to combine the functions of each different switches into one button so all lights are on when i click it, however, only two functions were executed when i clicked the button.

    <div><button v-on:click="onLightar(); onLightmngr(); onLightfy(); onLightmr(); onLightT(); onLightbr();" >Switch on all groundfloor lights </button></div>
  • 4
    perhaps the functions themselves are the issue - if two are executed (which two, you didn't mention) then there's nothing stopping you from doing 6 - personally, I'd write a function that runs those functions and call that function instead – Jaromanda X Aug 29 '22 at 08:01
  • answered here: https://stackoverflow.com/questions/38744932/how-to-call-multiple-functions-with-click-in-vue – BehRouz Aug 29 '22 at 08:15
  • can you provide function definitions ... – ht006 Aug 29 '22 at 13:23

1 Answers1

0

To make it simple and easy to understand, You can just call a single method on click and then invoke all the switches methods from that method.

In Template :

<div>
  <button v-on:click="switchOnAllLights">Switch on all groundfloor lights </button>
</div>

In Script :

switchOnAllLights() {
    this.onLightar();
    this.onLightmngr();
    this.onLightfy();
    this.onLightmr();
    this.onLightT();
    this.onLightbr();
}
Debug Diva
  • 26,058
  • 13
  • 70
  • 123