wxml部分
<van-uploader file-list="{{ picture_list }}" preview-full-image="{{false}}" max-size="2048000" max-count="9" multiple="{{true}}" bind:after-read="afterRead" bind:delete="deleteImg" />
js部分
afterRead:function(event) {
const { file } = eventdetail;
// 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
var obj={}
objpath=file;
thisuploadimg(obj);
},
uploadimg:function(data) {
wxshowLoading({
title:'上传中',
mask:true,
})
var that =this,
i = datai datai :0,
success = datasuccess datasuccess :0,
fail = datafail datafail :0;
let userInfo=wxgetStorageSync('userInfo');
let peopleId=userInfopeopleId;
var picture_list = thatdatapicture_list;
wxuploadFile({
url: baseUrl +'impl/uploadImg',
filePath: datapath[i]path,
name:'file',
formData: {
'type':1,
'peopleId':peopleId,
},
success: (res) => {
wxhideLoading();
success++;
let obj = JSONparse(resdata)data;
if(objhasOwnProperty('url')){
picture_listpush({
url:objurl,
id:objid
});
thatsetData({
picture_list
})
}
},
fail: (err) => {
wxhideLoading();
wxshowToast({
title:'上传失败!',
icon:'none'
})
fail++;
},
complete: () => {
i++;
if (i == datapathlength) {//当传完时,停止调用
}else {//若还没有传完,则继续调用函数
datai = i;
datasuccess = success;
datafail = fail;
thatuploadimg(data);//递归,回调自己
}
}
});
},
deleteImg(e) {
let index=edetailindex;
consolelog(index);
let {picture_list}=thisdata;
let that=this;
wxshowModal({
content:'确定删除?',
success: (res) => {
if (resconfirm) {
picture_listsplice(index,1);
thatsetData({
picture_list
})
consolelog(thatdatapicture_list);
}else if (rescancel) {
consolelog('用户点击取消')
}
},
})
},
以上就是关于微信小程序,引用vant-weapp库,上传组件uploader,支持多选全部的内容,包括:微信小程序,引用vant-weapp库,上传组件uploader,支持多选、、等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)