唯一的信仰
侠客
侠客
  • 最后登录2020-10-15
  • 发帖数5
阅读:8390回复:0

[微信小程序]小程序wx.previewImage实现点击图片进行预览

楼主#
更多 发布于:2018-01-01 21:12
1. 在页面上
    <view wx:for="pw_imgurlArr "  wx:key='index' class="previewimg">  
        <image src="pw_imgurlArr[index]" data-src="pw_imgurlArr[index]" bindtap=" imgClick"></image>  
    </view>  
2. 在js中定义预览图片的路径
data: {
    imgurlArr : [
&#039;http://i.gtimg.cn/music/photo/mid_album_300/c/I/002KSDg90IaScI.jpg&#039;
,&#039;http://i.gtimg.cn/music/photo/mid_album_300/c/I/002KSDg90IaScI.jpg&#039;,
 &#039;http://i.gtimg.cn/music/photo/mid_album_300/c/I/002KSDg90IaScI.jpg&#039;
      ]
}
  这里的图片的地址是http或https网络协议的网路图片地址(接口地址),网上说本地的图片地址不可以
3.js中定义点击事件
 imgClick:function(e){
 var src = e.currentTarget.dataset.src;//获取data-src
 var imgList = e.currentTarget.dataset.list;//获取data-list
 //图片预览
 wx.previewImage({
  current: src, // 当前显示图片的http链接,可以不写,不写默认显示第一张
  urls: imgList // 需要预览的图片http链接列表,这个字段必须有,这里是一个数组,且数组中直接放的就是地址,
                      //格式例如['http://XXXX']
 })
 }
游客


返回顶部

公众号

公众号