2c5faf30
梁灏
init Avatar compo...
|
1
|
<template>
|
a1530fac
梁灏
update Avatar
|
2
3
4
5
|
<span :class="classes">
<img :src="src" v-if="src">
<span :class="[prefixCls + '-string']" v-else-if="$slots.default"><slot></slot></span>
<Icon :type="icon" v-else-if="icon"></Icon>
|
2c5faf30
梁灏
init Avatar compo...
|
6
7
8
|
</span>
</template>
<script>
|
a1530fac
梁灏
update Avatar
|
9
10
11
|
import Icon from '../icon';
import { oneOf } from '../../utils/assist';
|
2c5faf30
梁灏
init Avatar compo...
|
12
13
14
15
|
const prefixCls = 'ivu-avatar';
export default {
name: 'Avatar',
|
a1530fac
梁灏
update Avatar
|
16
|
components: { Icon },
|
2c5faf30
梁灏
init Avatar compo...
|
17
|
props: {
|
a1530fac
梁灏
update Avatar
|
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
shape: {
validator (value) {
return oneOf(value, ['circle', 'square']);
},
default: 'circle'
},
size: {
validator (value) {
return oneOf(value, ['small', 'large', 'default']);
},
default: 'default'
},
src: {
type: String
},
icon: {
type: String
}
|
2c5faf30
梁灏
init Avatar compo...
|
36
37
38
|
},
data () {
return {
|
c5a721ad
梁灏
update
|
39
|
prefixCls: prefixCls
|
2c5faf30
梁灏
init Avatar compo...
|
40
41
42
|
};
},
computed: {
|
a1530fac
梁灏
update Avatar
|
43
44
45
46
47
48
49
50
51
52
53
|
classes () {
return [
`${prefixCls}`,
`${prefixCls}-${this.shape}`,
`${prefixCls}-${this.size}`,
{
[`${prefixCls}-image`]: !!this.src,
[`${prefixCls}-icon`]: !!this.icon
}
];
}
|
2c5faf30
梁灏
init Avatar compo...
|
54
55
56
57
58
59
|
},
methods: {
}
};
</script>
|