<template>
<view class="head" @click="selectImage">
<image :src="avatarUrl || '/static/head.png'" mode=""></image>
<span>点击获取头像</span>
</view>
</template>
<script>
export default {
data() {
return {
avatarUrl: '', // 用于保存头像的URL
};
},
methods: {
// 获取头像
selectImage() {
uni.chooseImage({
count: 1,
sizeType: ['compressed'],
sourceType: ['album', 'camera'],
success: (res) => {
const tempFilePaths = res.tempFilePaths;
if (tempFilePaths.length > 0) {
this.avatarUrl = tempFilePaths[0];
uni.setStorageSync('avatarUrl', this.avatarUrl);
}
}
});
},
}
};
</script>
uniapp获取头像
于 2024-09-13 11:41:01 首次发布