小程序--图片添加、删除

来源:互联网 发布:如何查看淘宝等级 编辑:程序博客网 时间:2024/04/26 06:15
 首先在data定义一个存放图片的数组
例:img[]
然后在wxml 用wx.for循环出img的数据即可
scImg: function () {
var that = this;
wx.chooseImage({
count: 6,
success: function (res) {
var tempFilePaths = res.tempFilePaths;
var imgList = that.data.img;
for (var iin tempFilePaths){
imgList.push(tempFilePaths[i])
}
that.setData({
img: imgList
})
}
})

},

delImg: function (e) {
var index = e.currentTarget.dataset.index;
var Img = this.data.img;
var that = this;
wx.showModal({
title: '提示',
content: '确定要删除此商品吗?',
success: function (res) {
if (res.confirm) {
console.log('用户点击确定')
Img.splice(index, 1);
} else if (res.cancel) {
return false
console.log('用户点击取消')
}
that.setData({
img: Img
});
}
})
},

原创粉丝点击