横向滑块查看大图省流

在uniapp的手机端中,纵向列表点击缩略图查看原图时,原图通常以满屏显示,并且可以通过左右滑动来切换上一张和下一张图片。

加载全部原图会占用大量的带宽以及浪费用户流量

应该获取当前图片以及前后两张图片

【includes】函数判断【readImgs】数组中是否含有当前图片位置,不存在就不显示,就不用先加载图片

<swiper circular :current="currentIndex" @change="swiperChange">
	<swiper-item 
        v-for="(item,index) in classList" 
        :key="index"
        @click="swiperChange(index)"
    >
		<image v-if="readImgs.includes(index)" :src="item.picurl" mode="aspectFill">		</image>
	</swiper-item>
</swiper>
// 图片数组
const classList = ref([{picurl:"xxx"},...]);
// 已加载的图片的位置的数组
const readImgs = ref([]);
// 当前原图的位置
const currentIndex = ref(0)

const swiperChange = (e) => {
    currentIndex.value = e.detail.current;
    readImgsFun();
}

function readImgsFun() {
    readImgs.value.push(
        currentIndex.value <= 0 ? classList.value.length - 1 : currentIndex.value - 1,
        currentIndex.value,
        currentIndex.value >= classList.value.length - 1 ? 0 : currentIndex.value + 1
    )
    readImgs.value = [...new Set(readImgs.value)];
}

注:vue3写法,未调试

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值