Commit 1d5d6ef6097f1fb101751034d982764a4ca317cd

Authored by 梁灏
1 parent 4c534a77

fixed #5136

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