UserAvatar.vue
899 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
<template>
<div class="change-avatar">
<CropperAvatar
ref="cropperRef"
:value="avatar"
:showBtn="false"
@change="handelUpload"
:btnProps="{ preIcon: 'ant-design:cloud-upload-outlined' }"
width="120px"
/>
</div>
</template>
<script setup lang="ts">
import { computed, ref } from 'vue'
import { propTypes } from '@/utils/propTypes'
import { CropperAvatar } from '@/components/Cropper'
import { uploadAvatarApi } from '@/api/system/user/profile'
const props = defineProps({
img: propTypes.string.def('')
})
const avatar = computed(() => {
return props.img
})
const cropperRef = ref()
const handelUpload = async ({ data }) => {
await uploadAvatarApi({ avatarFile: data })
cropperRef.value.close()
}
</script>
<style scoped lang="scss">
.change-avatar {
img {
display: block;
margin-bottom: 15px;
border-radius: 50%;
}
}
</style>