<image class="user-avatar" :src="signUpForm.avatar||'/static/icon/tab-bar/me.png'" mode="aspectFit"
@tap="changeAvatar(signUpForm)" ></image>
function changeAvatar(signUpForm) {
// #ifdef MP
uni.showModal({
title: "提示",
content: "因小程序无法直接截取图片,所以您应该提供一个宽高比为1:1的图片,且图片大小不超过1MB",
showCancel: false,
confirmText: "我知道了",
success() {
getImageMP(signUpForm);
}
})
// #endif
// #ifdef APP-PLUS
getImage(signUpForm);
// #endif
}
function getImage(signUpForm) {
uni.chooseImage({ // 从相册选择图片
count: 1,
crop: {
width: 500,
height: 500,
resize: true,
},
sizeType: "original",
success: (e) => { // 这里存在一个bug,在自定义调试基座下,如果是从相册中选择的照片,无法在头像位置显示。
console.log(e);
signUpForm.avatar = e.tempFilePaths[0]; // 将临时的文件路径放到头像中
},
fail: (e) => {
console.log(e);
if (e.errCode !== 0) {
uni.showToast({
icon: 'none', // 无图标
position: 'bottom', // 显示位置在屏幕下方,仅APP有效
title: "获取图片失败",
})
}
}
})
}
0 个回复