1

Is there a way to accomplish this in vue:

<button @click="(true) ? funcA : FuncB"> Click </button> 

In this case, the event is a click, but it could be a keypress, keydown, input and whatever else is on the vuejs docs.

If that's just not possible, what's the best way to accomplish the above without doing code repetition?

1 Answer 1

2

You could use an arrow function like :

@click="()=>{(true) ? funcA() : FuncB()}" 
Sign up to request clarification or add additional context in comments.

2 Comments

It actually worked but only if I add the parenthesis with the function, do you know why is that?
you should execute the methods by adding the () because the click event has already a handler which is the arrow function ()=>,

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.