changeAvatar:
function
() {
var
that =
this
;
wx.chooseImage({
count: 1,
sizeType: [&
#39;compressed'], // original 原图,compressed 压缩图,默认二者都有
sourceType: [&
#39;album', 'camera'], // album 从相册选图,camera 使用相机,默认二者都有
success:
function
(res) {
console.log(res.tempFilePaths +
"修改页面"
)
var
avatar = res.tempFilePaths;
that.setData({
avatar: avatar,
upAvatar:
true
})
},
fail:
function
() {
},
complete:
function
() {
}
})
},
这是是调用上传头像uploadFile方法
APP.uploadimg({
url: &
#39;URL地址',
path: avatar,
header: {
&
#39;Content-Type': 'multipart/form-data',
"Authorization"
:
"Bearer "
+ token
},
isShow:
false
});
上传头像代码uploadFile做了一个封装 代码放在APP.js里
uploadimg:
function
(data){
var
that=
this
,
i=data.i ? data.i : 0,
success=data.success ? data.success : 0,
fail=data.fail ? data.fail : 0;
wx.uploadFile({
url: data.url,
filePath: data.path[i],
name: &
#39;fileData',//这里根据自己的实际情况改
header: data.header,
formData: {
sequence:i+1
},
success: (resp) => {
success++;
console.log(resp)
console.log(i+
"成功"
);
}
},
fail: (res) => {
fail++;
console.log(&
#39;fail:' + i + "fail:" + fail);
},
complete: () => {
console.log(i);
i++;
if
(i == data.path.length) {
console.log(&
#39;执行完毕');
console.log(&
#39;成功:' + success + " 失败:" + fail);
}
else
{
console.log(i);
data.i = i;
data.success = success;
data.fail = fail;
that.uploadimg(data);
}
}
});
},
暂时没有评论,来抢沙发吧~