const tempFilePath = await new Promise((resolve, reject) => {
wx.chooseMedia()({
count: 1,
mediaType: ['image'],
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
const { path, size } = res.tempFiles[0];
if (size <= 10485760) {
resolve(path);
} else {
reject({ errMsg: '图片大小超出限制,请重新上传' });
}
},
fail: (err) => reject(err),
});
});
const tempUrlArr = tempFilePath.split('/');
const tempFileName = tempUrlArr[tempUrlArr.length - 1];
Toast({
context: this,
selector: '#t-toast',
message: `已选择图片-${tempFileName}`,
theme: 'success',
});
} catch (error) {
console.log(error)
if (error.errMsg === 'chooseImage:fail cancel') return;
Toast({
context: this,
selector: '#t-toast',
message: error.errMsg || error.msg || '修改头像出错了',
theme: 'error',
});
}
这里多了括号。