//先给img src绑定变量
<img :src="imgUrl" @error="getUrlImg()" alt />
//第一个图片地址
let imga = 'https://oss.jdb.hffss.com/aqc/basicInfomation/logo/'+ _this.$route.query.corpId +'.png'
//第二个图片地址
let imgb = 'https://oss.jdb.hffss.com/logo/'+ _this.$route.query.corpId +'.png'
//处理接口数据调用图片是否请求成功的方法
_this.imgpath1(imga).then(()=>{
//成功的话将第一个地址塞进去
_this.$set(_this,'imgUrl',imga)
}).catch(()=>{
//失败的话将第二个地址塞进去
_this.$set(_this,'imgUrl',imgb)
})
//上面两个都失败 onnerror将第三个图片塞进去
getUrlImg: function() {
var _this = this;
var src = require("../../assets/img/icon/managerdetail.gif");
_this.imgUrl = src;
},
//判断图片路径
imgpath1(imgurl) {
return new Promise(function(resolve, reject) {
var ImgObj = new Image();
ImgObj.src = imgurl;
ImgObj.onload = function(res) {
resolve(res);
}
ImgObj.onerror = function(err) {
reject(err)
}
})
},