2c5faf30
梁灏
init Avatar compo...
|
1
|
<script>
|
a1530fac
梁灏
update Avatar
|
2
3
4
|
import Icon from '../icon';
import { oneOf } from '../../utils/assist';
|
2c5faf30
梁灏
init Avatar compo...
|
5
6
7
8
|
const prefixCls = 'ivu-avatar';
export default {
name: 'Avatar',
|
2c5faf30
梁灏
init Avatar compo...
|
9
|
props: {
|
a1530fac
梁灏
update Avatar
|
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
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...
|
28
|
},
|
2c5faf30
梁灏
init Avatar compo...
|
29
|
computed: {
|
a1530fac
梁灏
update Avatar
|
30
31
32
33
34
35
36
37
38
39
40
|
classes () {
return [
`${prefixCls}`,
`${prefixCls}-${this.shape}`,
`${prefixCls}-${this.size}`,
{
[`${prefixCls}-image`]: !!this.src,
[`${prefixCls}-icon`]: !!this.icon
}
];
}
|
2c5faf30
梁灏
init Avatar compo...
|
41
|
},
|
ececc3bb
梁灏
update Avatar
|
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
render (h) {
let innerNode = '';
if (this.src) {
innerNode = h('img', {
attrs: {
src: this.src
}
});
} else if (this.icon) {
innerNode = h(Icon, {
props: {
type: this.icon
}
});
} else if (this.$slots.default) {
innerNode = h('span', {
'class': `${prefixCls}-string`
}, this.$slots.default);
}
|
2c5faf30
梁灏
init Avatar compo...
|
62
|
|
ececc3bb
梁灏
update Avatar
|
63
64
65
|
return h('span', {
'class': this.classes
}, [innerNode]);
|
2c5faf30
梁灏
init Avatar compo...
|
66
67
68
|
}
};
</script>
|