Home > Software design >  Conditional Vuejs Click Event Binding
Conditional Vuejs Click Event Binding

Time:09-29

I only want to add a click event when !date.disabled || date.availability === 'none'. How can I do that?

<div  
  @click="!date.disabled || date.availability !== 'none' ? selectDate(date) : null">
  {{date}}
</div>

CodePudding user response:

You could just try <button @click="(!date.disabled || date.availability !== 'none') ? selectDate() : null">Greet</button>

Working Fiddle

CodePudding user response:

You can simply achieve it by using an AND (&&) operator without using ternary operator.

@click="(!date.disabled || date.availability !== 'none') && selectDate(date)"

If condition passed then only selectDate method will get trigger else nothing will happen.

  • Related