iview/src/components/avatar/avatar.vue

59 lines
1.5 KiB
Vue
Raw Normal View History

2017-08-15 10:07:15 +08:00
<template>
2017-08-15 11:03:20 +08:00
<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>
2017-08-15 10:07:15 +08:00
</span>
</template>
<script>
2017-08-15 11:03:20 +08:00
import Icon from '../icon';
import { oneOf } from '../../utils/assist';
2017-08-15 10:07:15 +08:00
const prefixCls = 'ivu-avatar';
export default {
name: 'Avatar',
2017-08-15 11:03:20 +08:00
components: { Icon },
2017-08-15 10:07:15 +08:00
props: {
2017-08-15 11:03:20 +08:00
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
}
2017-08-15 10:07:15 +08:00
},
data () {
return {
2017-08-15 10:15:35 +08:00
prefixCls: prefixCls
2017-08-15 10:07:15 +08:00
};
},
computed: {
2017-08-15 11:03:20 +08:00
classes () {
return [
`${prefixCls}`,
`${prefixCls}-${this.shape}`,
`${prefixCls}-${this.size}`,
{
[`${prefixCls}-image`]: !!this.src,
[`${prefixCls}-icon`]: !!this.icon
}
];
}
2017-08-15 10:07:15 +08:00
},
methods: {
}
};
</script>