KinsDotNet
KinsDotNet

Reputation: 1560

How can I output a boolean variable as "yes/no" in VueJS 0.11?

I have a field called is_admin. I am using VueJS to build a autocompleting search of all of the users.

I want to output the is_admin field as either true/false or yes/no, but my database field is boolean, 1 or 0.

How can I output the value in a readable way instead of as the boolean field?

Upvotes: 2

Views: 4565

Answers (2)

Peter
Peter

Reputation: 12711

If you need to do this more than once, you might consider putting the logic in a filter:

Vue.filter('yesno', function (value) {
  return value ? 'Yes' : 'No';
})

and then use it like this:

<div>
  Admin? {{ is_admin | yesno }}
</div>

Upvotes: 12

Jeff
Jeff

Reputation: 25221

Try something like this:

<span>{{ user.is_admin ? "Admin" : "User" }}</span>

Upvotes: 10

Related Questions