最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How can I output a boolean variable as "yesno" in VueJS 0.11? - Stack Overflow

programmeradmin6浏览0评论

I have a field called is_admin. I am using VueJS to build a autopleting 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?

I have a field called is_admin. I am using VueJS to build a autopleting 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?

Share Improve this question asked Feb 4, 2016 at 18:56 KinsDotNetKinsDotNet 1,5605 gold badges27 silver badges59 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 12

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>

Try something like this:

<span>{{ user.is_admin ? "Admin" : "User" }}</span>
发布评论

评论列表(0)

  1. 暂无评论