在使用uni.previewImage()方法的时候会发现,时间执行后一直黑屏加载,如下所示
该如何解决,出现这种情况,我们查看一下我们的图片地址是否是本地,如果是本地,那么将图片转为网络图片即可
话不多说,直接看代码:
<view class="main">
<image :src="recomList[tabIndex].image" mode="" @click="scala(recomList[tabIndex].image)"></image>
</view>
因为我是请求到的数据,数据中格式是这样的
所以我直接用拼接的方式解决 ,
可能有人用的是本地图片,可以使用Postimages — free image hosting / image upload
来将图片转换为链接
methods: {
scala(e){
//console.log(e)
let url = 'https:' + e
let imgUrl = []
imgUrl.push(e)
//console.log(imgUrl)
uni.previewImage({
urls: imgUrl, //需要预览的图片http链接列表
current: imgUrl[0], // 当前显示图片的http链接,默认是第一个(可以是图片地址,也可以是下标)
})
}
}
最终效果: