我有一个简单的问题,希望你能帮忙:
<div>
<figure :style="{ 'background': 'url(' + item.main_featured + ') center no-repeat' }">
</div>
如果来自 API 的 URL 未定义,我希望样式属性“背景”返回颜色
例子:
如果 item.featured_photo 不为空:
<figure style="background: url('localhost:6969/image.img') center no-repeat">
如果 item.featured_photo 为空:
<figure style="background: #FFF">
原文由 KitKit 发布,翻译遵循 CC BY-SA 4.0 许可协议
V-bind:style VueJS 中的使用条件:
这是最小的例子,
如果您需要 Parent-Child-Conditions ,那么这就是魔法:
简而言之:
希望能帮助到你!