uni.previewImage是uniapp提供的预览图片的方法

1.准备结构

<view v-for="(item,index) in photos" :key="index">
//点击当前图片传入索引							
	<image :src="item.pics_small_url"  @click="getImgIndex(index)"></image>					
</view>

2.实现功能

<script>
	export default {
		data() {
			return {
				photos: [] // 存放从后台获取的数据 
			};
		},
		methods: {
			getImgIndex(index){
				console.log(index);
				//准备一个装图片路径的  数组imgs
				let imgs = this.photos.map( item =>{
                //只返回图片路径
					return item.pics_big_url  
				})
				// console.log(imgs);
                //调用预览图片的方法
				uni.previewImage({
					urls:imgs,
					current:index
				})
			}
		}
	}
</script>

 

Logo

基于 Vue 的企业级 UI 组件库和中后台系统解决方案,为数万开发者服务。

更多推荐