//图片预览
previewImg: function (e) {
var that = this;
console.log(e.currentTarget.dataset.index);
var index = e.currentTarget.dataset.index;
var imgs = this.data.imgs;
var imgurl = that.data.imgurl;
wx.previewImage({
current: imgs[index], //当前图片地址
urls: imgs, //所有要预览的图片的地址集合 数组形式
success: function (res) { },
fail: function (res) { },
complete: function (res) { },
})
}
<view class='imgs' >
<block wx:for="{{imgs}}" wx:key='index'>
<image src='{{item}}' bindtap='previewImg' data-url="{{imgurl}}{{item}}" data-index='{{index}}'></image>
</block>
</view>
data: {
imgurl: '../../image/',
imgs: [ //小程序只能预览网络图片不能预览本地图片
'../../image/1@2x.png',
'../../image/2@2x.png',
'../../image/3@2x.png',
'../../image/4@2x.png',
'../../image/5@2x.png',
'../../image/6@2x.png',
'../../image/7@2x.png',
'../../image/8@2x.png',
'../../image/9@2x.png',
],
// imgs1:[
// 'https://gs.wyjzpw.com/images/jiudiananli@2x.png',
// 'https://gs.wyjzpw.com/images/xuexiaoanli@2x.png',
// 'https://gs.wyjzpw.com/images/yiyuananli@2x.png',
// 'https://gs.wyjzpw.com/images/qiyeanli@2x.png'
// ]
},
//图片预览
previewImg: function (e) {
var that = this;
console.log(e.currentTarget.dataset.index);
var index = e.currentTarget.dataset.index;
var imgs = this.data.imgs;
var imgurl = that.data.imgurl;
wx.previewImage({
current: imgs[index], //当前图片地址
urls: imgs, //所有要预览的图片的地址集合 数组形式
success: function (res) { },
fail: function (res) { },
complete: function (res) { },
})
}
贴代码片段 谢谢。你这样提问题 谁知道什么原因。