changeUpdata(ev){
console.log(ev);
let types = ev.currentTarget.dataset.type;//主图1,详情图2
let that = this;
wx.chooseImage({
count: 1, // 默认9
sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
success(res) {
wx.showLoading({ title: '上传中' })//加载中
const tempFilePaths = res.tempFilePaths;
console.log(tempFilePaths[0]);
wx.uploadFile({
url: 'https://kdc.api.meijiangkj.com/' + API.UPLOADIMG,
filePath: tempFilePaths[0],
name: 'file',
formData: {
'img': 'img'
},
success(res) {
console.log(res,'**');
if (res.statusCode == 200){
const data = JSON.parse(res.data)
console.log(res, data);
if (data.code == 200) {
if (types == 1) {
that.setData({ Img1: data.data, isUpdata1: true })//保存图片展示
} else if (types == 2) {
let ImgList = that.data.Img2;
that.setData({ Img2: ImgList.concat(data.data), isUpdata2: true })//保存图片展示
console.log(that.data.Img2);
}
wx.hideLoading();//关闭上传中
} else {
wx.hideLoading();//关闭上传中
wx.showToast({
title: data.msg,
icon: 'none'
})
}
}else {
wx.hideLoading();//关闭上传中
wx.showToast({
title: '上传错误',
icon:'none'
})
}
},
fail:res => {
console.log(res);
}
})
}
})
},
微信小程序学习之路(一)- 上传图片
最新推荐文章于 2024-04-23 20:45:44 发布