发请求的时候如果后台获取没有图片 想给几张默认随机图片
<img class="dou-img" :src="item.posterHeaderUrl" alt="" />
// 双选会随机图片
const getDefault = () => {
let i = Math.round(Math.random() * 3)
return '/default/sxh_0' + (i > 0 ? i : 1) + '.jpg'
}
在接口里判断
getDoubleListApi({
page: currentPage.value, //当前页码
pageSize: pageSize.value //每页条数
// keyword: keyword.value
}).then((res) => {
console.log('res', res)
if (res.code == '200') {
total.value = res.result.total
list.splice(0, list.length, ...res.result.items)
//判断随机图片
list.forEach((item) => {
if (!item.posterHeaderUrl) item.posterHeaderUrl = getDefault()
})
}
})