61 lines
992 B
Vue
61 lines
992 B
Vue
<template>
|
|
<view>
|
|
<view class="avatar-icon"></view>
|
|
<view class="avatar-image">
|
|
<image class="image-style" mode="aspectFill" :src="showImage" @error="imageError"></image>
|
|
</view>
|
|
<text class="avatar-text">{{name}}</text>
|
|
</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: 120px;
|
|
height: 120px;
|
|
}
|
|
|
|
.image-style {
|
|
width: 100%;
|
|
height: 100%;
|
|
}
|
|
|
|
.avatar-text {}
|
|
</style>
|