uni-app点击预览图片

uni-app点击预览图片

在uni-app中已经提供了预览图片的方法uni.previewImage,直接调用就可以了

如果是类似轮播图,是固定是几张图片,直接获取图片就行
html代码

<!-- 轮播图开始 -->
<view class="lunbo">
	<swiper 
		:indicator-dots="true" 
		:autoplay="false" 
		:acceleration="false" 
		:interval="3000" 
		:duration="1000">
		<swiper-item v-for="(lunbo,index) in detail.lunboImg" :key="index">
			<view class="swiper-item">
				<img 
					:src="lunbo" 
					:data-src="lunbo"  
					@tap="previewImage(index)" 
					class="swiper-item-img">
			</view>
		</swiper-item>
	</swiper>
</view>
<!-- 轮播图结束 -->
methods: {
	//预览轮播图
	previewImage:function(index){
		var i = this.detailList[0].lunboImg; //获取当前页面的轮播图数据
		//uniapp预览轮播图
		uni.previewImage({
			current:index, //预览图片的下标
			urls:i //预览图片的地址,必须要数组形式,如果不是数组形式就转换成数组形式就可以
		})
	}
}

如果是点击查看对应文字的图片,就要先将图片地址传到方法里面

html代码

<view class="SKU-title-img">
	<image 
		mode="aspectFit" 
		:src="imgUrl" 
		@tap="SKUpreviewImage(imgUrl,index)"
		class="title-img"></image>
</view>
<view class="color-name">
	<!-- 点击改变图片 -->
	<text 
		:class="activeColor == colorIndex ? 'active':''" 
		v-for="(color,colorIndex) in SKUList.color" 
		:key="colorIndex" 
		@click="colorImg(color[1],color[2],colorIndex)">{{color[0]}}</text>
</view>

js代码

data() {
	  imgUrl:''		//存放图片地址
	   };
	 },
methods: {
	//点击不同的颜色,改变图片地址
	colorImg:function(img){
		//定义一个变量
		var me = this;
		me.imgUrl = img;  //点击当前的颜色替换成当前颜色的图片
	},
	//SKU里面的图片预览
	SKUpreviewImage:function(image,index){
		//此方法传图片地址要数组的形式,所以定义一个数组,然后将内容push进去,再去做图片预览
		var arr = [];
		arr.push(image);
		//uniapp预览轮播图方法
		uni.previewImage({
			current:index, //预览图片的下标
			urls:arr //预览图片的地址,必须要数组形式
		})
	},
}
  • 10
    点赞
  • 30
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值