有条件的胡子显示 HTML 属性? [英] Mustache with condition display HTML attributes?

查看:34
本文介绍了有条件的胡子显示 HTML 属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在 Vue mustache 中显示 HTML 属性?

{{ (data.status)?<div>活动</div>":"<div>InActive</div>>>>}}

解决方案

不能在 mustache 表达式中添加 HTML.它会导致不计算表达式.

https://jsfiddle.net/0zaknb56/

您可以做的是使用 v-html 指令

<div v-html="data.status ?`<div>活动</div>`:`<div>非活动</div>`">

https://jsfiddle.net/7h6osyt9/

Is it possible to display HTML attributes in Vue mustache?

{{ (data.status)? "<div>Active</div>" : "<div>InActive</div>"}}

解决方案

You cannot add HTML within a mustache expression. It causes the expression to not be evaluated.

https://jsfiddle.net/0zaknb56/

What you can do is use the v-html directive

<div v-html="data.status ? `<div>Active</div>` : `<div>Inactive</div>`">
</div>

https://jsfiddle.net/7h6osyt9/

这篇关于有条件的胡子显示 HTML 属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆