小程序-uni.previewImage实现图片的预览功能
uni.previewImage是uniapp提供的预览图片的方法1.准备结构<view v-for="(item,index) in photos" :key="index">//点击当前图片传入索引<image :src="item.pics_small_url"@click="getImgIndex(index)"></image></view>
·
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>
更多推荐
已为社区贡献2条内容
所有评论(0)