2021-08-27 提前验证图片404

2021-08-27  本文已影响0人  王小博er

<img :onerror="errorImg" style="width:0.6rem;height:0.6rem" :src="item" @click="showimgDialog(item,'image')"

showimgDialog(item,type){
          let _this = this
          const createCORSRequest = (method,url)=>{
            var xhr = new XMLHttpRequest();
            if("withCredentials"in xhr){
              xhr.open(method,url,true);
            } else if(typeof XDomainRequest!="undefined"){
              xhr = new XDomainRequest();
              xhr.open(method,url);
            } else {
              xhr = null;
            }
              return xhr;
          }
          var xhr = createCORSRequest('GET',item);
          xhr.onerror = function(){
                    MessageBox("提示", "图片加载失败");
          };
          xhr.onload = function(){
            if (type === 'image') {
              _this.imgDialogList=[ item ]
              _this.imgDialog=true
            }else{
              _this.dialog = true
              _this.videourl = item
            }
          };
          xhr.send();
            },
上一篇下一篇

猜你喜欢

热点阅读