本文首发自个人自有博客:【FaxMiao个人博客】,一个关注Web前端开发技术、关注用户体验、记录前端点滴,坚持更多原创,为大家提供高质量技术博文!
定义初始数据:
data: {
imgList: [], // 图片集合
baseImg: [], // base64图片集合
maxImg: 8, // 图片上传最高数量(根据需求设置)
}
第一步:从本地相册选择图片或使用相机拍照(wx.chooseImage)
// 选择图片
selectPictures: function () {
const that = this;
// 最多上传图片数量
if (that.data.imgList.length < that.data.maxImg) {
wx.chooseImage({
// 最多可以选择的图片张数(最大数量-当前已上传数量)
count: that.data.maxImg - that.data.imgList.length,
sizeType: "compressed",
success: function (res) {
for (let i = 0; i < res.tempFilePaths.length; i++) {
that.data.imgList.push(res.tempFilePaths[i]);
}
// 显示图片(同步渲染到页面)
t