Call Methods with JavaScript expressions?

Can you call methods when using JavaScript expressions?

For example:

Using a Javascript expression like

{{ ok ? 'YES' : 'NO' }}

instead of “yes” and “no”, can I replace them with method calls? so that if it is true, 1 method will get called, but if it’s false, a different method will get called? If that makes sense…

Are you doing this in the template?

The short answer is yes. The longer answer is that if you are doing this in the template, you should use a computed property to avoid unnecessary function calls during re-render.

1 Like

Yes, in the template. I essentially am trying to bring up a modal and in the modal it lists a collection of names and emails (as input tags) from a for loop, which i grab from my rails database. But if a record has a name, but no accompanying email. I would only want it to display the name with no email input box

Here is an image of my Modal. But right now it will put the email input box regardless if it is empty or not.

So my thinking was to do something like

{{ ? includeEmail() : ignoreEmail() }}

inside my template

A simple v-if should be all you need.

<input v-if="" />

Ah yes! I over thought that ay too much. thanks!