小程序
小游戏
企业微信
微信支付
扫描小程序码分享
clickImg: function(e) { console.log("xxxxxxxxxxx") var imgUrl = this.data.imgUrl; var current = e.target.dataset.src; wx.previewImage({ urls: imgUrl, current: current, }) },
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
几行代码解决你的问题:
<view class="bg-img" wx:for="{{ImgFileIDList}}" wx:key="index" > <image lazy-load="true" mode='aspectFill' src="{{item}}" data-index="{{index}}" bindtap="ViewImage"/> </view> //js代码 //展示预览图片 ViewImage(e) { let index = e.currentTarget.dataset.index //ImgFileIDList为自己要展示图片的数组 let imgAry = this.data.ImgFileIDList wx.previewImage({ urls: imgAry, current: imgAry[index] }) },
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
previewImage里面的urls参数应该是数组,是你待预览的图片的数组,比如
['sss.com/xxx1.jpg','sss.com/xxx2.jpg'....]
这个设置对了你的问题就解决了
相关文档:
wx.previewImage(Object object) | 微信开放文档
https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.previewImage.html
<view class="blockDiv" >
<view class="block" wx:for="{{imgUrl}}" wx:key="imgUrl">
<image bindtap = "clickImg" class="bdimg" mode='aspectFill' lazy-load='true' src="{{imgUrl[index]}}"></image>
</view>
-------------------------------------------------------------
clickImg: function(e) {
console.log("xxxxxxxxxxx")
var imgUrl = this.data.imgUrl;
var current = e.target.dataset.src;
wx.previewImage({
urls: imgUrl,
current: current,
})
},
写了个代码片段,问题未复现:
https://developers.weixin.qq.com/s/9awVAXm67HfF
wxml里
<image bindtap="clickImg" class="bdimg" mode='aspectFill' lazy-load src="{{imgUrl[index]}}" data-url="{{imgUrl[index]}}" />
js里:
clickImg(e) {
var urls = this.data.imgUrl;
var current = e.currentTarget.dataset.url;
urls,
current
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
几行代码解决你的问题:
<view class="bg-img" wx:for="{{ImgFileIDList}}" wx:key="index" > <image lazy-load="true" mode='aspectFill' src="{{item}}" data-index="{{index}}" bindtap="ViewImage"/> </view> //js代码 //展示预览图片 ViewImage(e) { let index = e.currentTarget.dataset.index //ImgFileIDList为自己要展示图片的数组 let imgAry = this.data.ImgFileIDList wx.previewImage({ urls: imgAry, current: imgAry[index] }) },
previewImage里面的urls参数应该是数组,是你待预览的图片的数组,比如
['sss.com/xxx1.jpg','sss.com/xxx2.jpg'....]
这个设置对了你的问题就解决了
相关文档:
wx.previewImage(Object object) | 微信开放文档
https://developers.weixin.qq.com/miniprogram/dev/api/media/image/wx.previewImage.html
<view class="blockDiv" >
<view class="block" wx:for="{{imgUrl}}" wx:key="imgUrl">
<image bindtap = "clickImg" class="bdimg" mode='aspectFill' lazy-load='true' src="{{imgUrl[index]}}"></image>
</view>
</view>
-------------------------------------------------------------
clickImg: function(e) {
console.log("xxxxxxxxxxx")
var imgUrl = this.data.imgUrl;
var current = e.target.dataset.src;
wx.previewImage({
urls: imgUrl,
current: current,
})
},
另外,你可以直接用item代替imgUrl[index]
wx:key="*this"
因为你js里有这一句,所以wxml里要有对应的data-src,不然js里的e.target.dataset.src为空的
写了个代码片段,问题未复现:
https://developers.weixin.qq.com/s/9awVAXm67HfF
<view class="blockDiv" >
<view class="block" wx:for="{{imgUrl}}" wx:key="imgUrl">
<image bindtap = "clickImg" class="bdimg" mode='aspectFill' lazy-load='true' src="{{imgUrl[index]}}"></image>
</view>
</view>
-------------------------------------------------------------
clickImg: function(e) {
console.log("xxxxxxxxxxx")
var imgUrl = this.data.imgUrl;
var current = e.target.dataset.src;
wx.previewImage({
urls: imgUrl,
current: current,
})
},
wxml里
<image bindtap="clickImg" class="bdimg" mode='aspectFill' lazy-load src="{{imgUrl[index]}}" data-url="{{imgUrl[index]}}" />
js里:
clickImg(e) {
var urls = this.data.imgUrl;
var current = e.currentTarget.dataset.url;
wx.previewImage({
urls,
current
})
},