Commit ececc3bb4cbcc1d0298d07aef197afc1bacc61bb

Authored by 梁灏
1 parent a1530fac

update Avatar

Showing 1 changed file with 23 additions and 14 deletions   Show diff stats
src/components/avatar/avatar.vue
1 -<template>  
2 - <span :class="classes">  
3 - <img :src="src" v-if="src">  
4 - <span :class="[prefixCls + '-string']" v-else-if="$slots.default"><slot></slot></span>  
5 - <Icon :type="icon" v-else-if="icon"></Icon>  
6 - </span>  
7 -</template>  
8 <script> 1 <script>
9 import Icon from '../icon'; 2 import Icon from '../icon';
10 import { oneOf } from '../../utils/assist'; 3 import { oneOf } from '../../utils/assist';
@@ -13,7 +6,6 @@ @@ -13,7 +6,6 @@
13 6
14 export default { 7 export default {
15 name: 'Avatar', 8 name: 'Avatar',
16 - components: { Icon },  
17 props: { 9 props: {
18 shape: { 10 shape: {
19 validator (value) { 11 validator (value) {
@@ -34,11 +26,6 @@ @@ -34,11 +26,6 @@
34 type: String 26 type: String
35 } 27 }
36 }, 28 },
37 - data () {  
38 - return {  
39 - prefixCls: prefixCls  
40 - };  
41 - },  
42 computed: { 29 computed: {
43 classes () { 30 classes () {
44 return [ 31 return [
@@ -52,8 +39,30 @@ @@ -52,8 +39,30 @@
52 ]; 39 ];
53 } 40 }
54 }, 41 },
55 - methods: { 42 + render (h) {
  43 + let innerNode = '';
  44 +
  45 + if (this.src) {
  46 + innerNode = h('img', {
  47 + attrs: {
  48 + src: this.src
  49 + }
  50 + });
  51 + } else if (this.icon) {
  52 + innerNode = h(Icon, {
  53 + props: {
  54 + type: this.icon
  55 + }
  56 + });
  57 + } else if (this.$slots.default) {
  58 + innerNode = h('span', {
  59 + 'class': `${prefixCls}-string`
  60 + }, this.$slots.default);
  61 + }
56 62
  63 + return h('span', {
  64 + 'class': this.classes
  65 + }, [innerNode]);
57 } 66 }
58 }; 67 };
59 </script> 68 </script>
60 \ No newline at end of file 69 \ No newline at end of file