70 lines
1.1 KiB
Vue
70 lines
1.1 KiB
Vue
<template>
|
|
<view>
|
|
<view class="avatar-icon"></view>
|
|
<view class="avatar-image">
|
|
<image class="image-style" mode="aspectFill" :src="showImage" @error="imageError"></image>
|
|
</view>
|
|
<view class="avatar-text"><text>{{name}}</text></view>
|
|
</view>
|
|
</template>
|
|
|
|
<script>
|
|
export default {
|
|
props: {
|
|
image: {
|
|
type: String,
|
|
default: ''
|
|
},
|
|
name: {
|
|
type: String,
|
|
default: '未知用户'
|
|
},
|
|
},
|
|
data() {
|
|
return {
|
|
defaultImage: require('@/static/image/errImage.jpeg'),
|
|
imageErrorStatus: false,
|
|
}
|
|
},
|
|
computed: {
|
|
showImage() {
|
|
if (this.imageErrorStatus) {
|
|
returnthis.defaultImage
|
|
} else {
|
|
return this.image || this.defaultImage
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
imageError() {
|
|
this.imageErrorStatus = true;
|
|
}
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style>
|
|
.avatar-icon {}
|
|
|
|
.avatar-image {
|
|
width: 130px;
|
|
height: 130px;
|
|
overflow: hidden;
|
|
border-radius: 50%;
|
|
}
|
|
|
|
.image-style {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.avatar-text {
|
|
width: 100%;
|
|
text-align: center;
|
|
color: #646566;
|
|
font-size: 24px;
|
|
height: 30px;
|
|
line-height: 30px;
|
|
}
|
|
</style>
|