Commit 1d5d6ef6097f1fb101751034d982764a4ca317cd

Authored by 梁灏
1 parent 4c534a77

fixed #5136

examples/routers/avatar.vue
@@ -32,6 +32,8 @@ @@ -32,6 +32,8 @@
32 </div> 32 </div>
33 <br><br><br> 33 <br><br><br>
34 <Avatar custom-icon="ivu-icon-ios-person" /> 34 <Avatar custom-icon="ivu-icon-ios-person" />
  35 +
  36 + <Avatar :src="src" size="large" @on-error="handleError" />
35 </div> 37 </div>
36 </template> 38 </template>
37 <script> 39 <script>
@@ -42,7 +44,8 @@ @@ -42,7 +44,8 @@
42 data () { 44 data () {
43 return { 45 return {
44 user: UserList[0], 46 user: UserList[0],
45 - color: ColorList[0] 47 + color: ColorList[0],
  48 + src: 'https://dev-file.iviewui.com/userinfoPDvn9gKWYihR24SpgC319vXY8qniCqj41/avatar'
46 } 49 }
47 }, 50 },
48 methods: { 51 methods: {
@@ -50,6 +53,9 @@ @@ -50,6 +53,9 @@
50 const index = UserList.indexOf(this.user); 53 const index = UserList.indexOf(this.user);
51 this.user = index < UserList.length - 1 ? UserList[index + 1] : UserList[0]; 54 this.user = index < UserList.length - 1 ? UserList[index + 1] : UserList[0];
52 this.color = index < ColorList.length - 1 ? ColorList[index + 1] : ColorList[0]; 55 this.color = index < ColorList.length - 1 ? ColorList[index + 1] : ColorList[0];
  56 + },
  57 + handleError () {
  58 + this.src = 'https://dev-file.iviewui.com/userinfoPDvn9gKWYihR24SpgC319vXY8qniCqj4/avatar';
53 } 59 }
54 } 60 }
55 } 61 }
src/components/avatar/avatar.vue
1 <template> 1 <template>
2 <span :class="classes"> 2 <span :class="classes">
3 - <img :src="src" v-if="src"> 3 + <img :src="src" v-if="src" @error="handleError">
4 <Icon :type="icon" :custom="customIcon" v-else-if="icon || customIcon"></Icon> 4 <Icon :type="icon" :custom="customIcon" v-else-if="icon || customIcon"></Icon>
5 <span ref="children" :class="[prefixCls + '-string']" :style="childrenStyle" v-else><slot></slot></span> 5 <span ref="children" :class="[prefixCls + '-string']" :style="childrenStyle" v-else><slot></slot></span>
6 </span> 6 </span>
@@ -89,6 +89,9 @@ @@ -89,6 +89,9 @@
89 this.scale = 1; 89 this.scale = 1;
90 } 90 }
91 } 91 }
  92 + },
  93 + handleError (e) {
  94 + this.$emit('on-error', e);
92 } 95 }
93 }, 96 },
94 mounted () { 97 mounted () {