绑定img的@error事件就可以
上代码:
<template>
<img
v-if="isHandImg"
:src="'https://zxyj-stor-test-01.oss-cn-shanghai.aliyuncs.com/' +userInfo.avatar"
alt=""
@error="defaultSrc"
/>
</template>
data() {
return {
userInfo: "",
isHandImg: true
};
},
created() {
this.userInfo = JSON.parse(getSessionStorage("userInfo"));
console.log(this.userInfo);
},
methods: {
defaultSrc() {
this.isHandImg = false;
},
},