javascript - 如何在带有 v-for 指令的组件内使用三元运算符?
问题描述
工作代码如下所示:
<template lang="pug">
b-carousel.d-none.d-sm-block(
id='categoryRoulette'
controls
no-animation
:interval='0'
)
b-carousel-slide(
v-for="category in chunkedArr"
:key="category.permalink"
)
template(v-slot:img)
b-card-group(deck)
b-card(
v-for="(item, index) in category" :key="index"
:img-src='item.image'
img-alt='Image'
img-top
tag='article'
style="min-width: 250px;"
)
b-card-text.d-flex.justify-content-center.align-items-center
h5
a(href="#") {{ item.title }}
</template>
但是,我需要检查 item.image 是否存在,如果不显示空白图像,如下所示:
<template lang="pug">
b-carousel.d-none.d-sm-block(
id='categoryRoulette'
controls
no-animation
:interval='0'
)
b-carousel-slide(
v-for="category in chunkedArr"
:key="category.permalink"
)
template(v-slot:img)
b-card-group(deck)
b-card(
v-for="(item, index) in category" :key="index"
:img-src='item.image ? item.image : '../assets/images/blank.png''
img-alt='Image'
img-top
tag='article'
style="min-width: 250px;"
)
b-card-text.d-flex.justify-content-center.align-items-center
h5
a(href="#") {{ item.title }}
</template>
但是,这条线不起作用:
:img-src='item.image ? item.image : '../assets/images/blank.png''
如何检查 item.image?也许,还有另一种方式?
解决方案
您不能'
在另一个中使用嵌套'
,因此将其更改为"
:img-src='item.image ? item.image : "../assets/images/blank.png"'
或者
:img-src="item.image ? item.image : '../assets/images/blank.png'"
推荐阅读
- sql - SQL - 如何根据条件插入表中?
- angular - Angular 5:如何为数据绑定属性编写 Jasmine 单元测试
- symfony - Symfony,如何在实体中获取当前用户(FOS),未使用的__construct()?
- c# - 将不同的条件传递给 linq where
- excel - 如何在数据验证列表中搜索数字?
- python - Python,为“if object”语句调用了哪个魔术方法
- entity-framework - 如何在 EntityFrameworkCore InMemory 中包含对象属性
- xml - 如何在 Eclipse 中像打开 XML 一样打开文件
- javascript - 如何检查我的扩展程序是否安装在访问特定网页的浏览器上?
- sql-server - 两个新列 SQL Server:一个带有记者 ID,一个带有每行记者数