是否有任何JavaScript方法可以阻止函数工作

问题描述 投票:1回答:2

我有一个函数,它有一个if语句和一个onclick函数。当if语句为真时,我想要整个函数不起作用。我试图做错返回,它对我不起作用

showLogo: function(row) {
  var a = 0;
  window.onclick = (e => {
    let element = e.target.className || e.srcElement.className
    let element1 = e.target || e.srcElement
    if (element1.localName == "li" || element == "pagination-previous" || element == "pagination-next" || element === "pagination-link" || element === "icon" || element === "fa fa-angle-right fa-lg" || element === "b-table" || element === "level" || element === "pagination" || element === "fa fa-angle-left fa-lg") {
      this.logo = false
    }
  });
  if (window.innerWidth > 1024) {
    this.logo = true;
    this.color = false;
    this.istabModalActive = false;
    this.name = row.fileName;
    this.dimension = row.width + ' x ' + row.height
    this.width = 0;
    this.height = 0;
    this.src = row.path;
    this.icon = row.iconsrc;
    this.dlsrc = row.path;
    this.contentType = row.contentType;
    this.typeshow = row.contentType.split("/")[1].toUpperCase();
    this.type = row.contentType.split("/")[1];
    this.icons = 'dist/' + this.type + '.svg';
    this.assetsid = row.index;
    this.size = row.size;
    this.activerow = row;
    this.fileid = row.id;
    this.assetsid = row.id;
    this.activerow = row;
  } else {
    this.logo = true;
    this.color = false;
    this.istabModalActive = true;
    this.filesarr = row;
    this.name = row.fileName;
    this.dimension = row.width + ' x ' + row.height
    this.size = row.size;
    this.src = row.path;
    this.icon = row.iconsrc;
    this.dlsrc = row.path;
    this.typeshow = row.contentType.split("/")[1].toUpperCase();
    this.type = row.contentType.split("/")[1];
    this.icons = row.iconsrc;
    this.fileid = row.id;
    this.assetsid = row.id;
    this.activerow = row;
  }

}
javascript ecmascript-6 vue.js frontend
2个回答
1
投票
showLogo:function(row){
    var a = 0;
    var flag = 0;
    window.onclick = (e => {
        let element = e.target.className || e.srcElement.className
        let element1 = e.target || e.srcElement
        if (element1.localName == "li" || element == "pagination-previous" || element == "pagination-next" || element === "pagination-link" ||  element === "icon" ||  element === "fa fa-angle-right fa-lg" ||  element === "b-table"||  element === "level"||  element === "pagination" ||  element === "fa fa-angle-left fa-lg") {
            this.logo = false;
            flag = 1;
        }


        }); 
                if(window.innerWidth> 1024 && flag == 0)
                {
                this.logo = true;
                this.color = false; 
                this.istabModalActive = false;
                this.name = row.fileName;
                this.dimension = row.width +' x '+row.height
                this.width = 0;
                this.height = 0;
                this.src = row.path;
                this.icon = row.iconsrc;
                this.dlsrc = row.path;
                this.contentType = row.contentType;
                this.typeshow = row.contentType.split("/")[1].toUpperCase() ;
                this.type = row.contentType.split("/")[1];
                this.icons = 'dist/'+this.type+'.svg';
                this.assetsid=row.index;
                this.size = row.size;
                this.activerow = row;
                this.fileid=row.id;
                this.assetsid=row.id;
                this.activerow = row;
                }
                else if(flag == 0) {
                this.logo = true;
                this.color = false; 
                this.istabModalActive = true;
                this.filesarr=row;
                this.name = row.fileName;
                this.dimension = row.width +' x '+row.height
                this.size = row.size;
                this.src = row.path;
                this.icon = row.iconsrc;
                this.dlsrc = row.path;
                this.typeshow = row.contentType.split("/")[1].toUpperCase() ;
                this.type = row.contentType.split("/")[1];
                this.icons = row.iconsrc;
                this.fileid=row.id;
                this.assetsid=row.id;
                this.activerow = row;   
                }

},

0
投票
setWindowOnCLick : function() {
  window.onclick = (e => {
        let element = e.target.className || e.srcElement.className
        let element1 = e.target || e.srcElement
        if (element1.localName == "li" || element == "pagination-previous" || element == "pagination-next" || element === "pagination-link" || element === "icon" || element === "fa fa-angle-right fa-lg" || element === "b-table" || element === "level" || element === "pagination" || element === "fa fa-angle-left fa-lg") {
          this.logo = false
        }
      });
}  
showLogo: function(row) {
      var a = 0;

      if (window.innerWidth > 1024) {
        this.logo = true;
        this.color = false;
        this.istabModalActive = false;
        this.name = row.fileName;
        this.dimension = row.width + ' x ' + row.height
        this.width = 0;
        this.height = 0;
        this.src = row.path;
        this.icon = row.iconsrc;
        this.dlsrc = row.path;
        this.contentType = row.contentType;
        this.typeshow = row.contentType.split("/")[1].toUpperCase();
        this.type = row.contentType.split("/")[1];
        this.icons = 'dist/' + this.type + '.svg';
        this.assetsid = row.index;
        this.size = row.size;
        this.activerow = row;
        this.fileid = row.id;
        this.assetsid = row.id;
        this.activerow = row;
      } else {
        this.logo = true;
        this.setWindowOnCLick.call(this)
        //thismay solve your problem
        this.color = false;
        this.istabModalActive = true;
        this.filesarr = row;
        this.name = row.fileName;
        this.dimension = row.width + ' x ' + row.height
        this.size = row.size;
        this.src = row.path;
        this.icon = row.iconsrc;
        this.dlsrc = row.path;
        this.typeshow = row.contentType.split("/")[1].toUpperCase();
        this.type = row.contentType.split("/")[1];
        this.icons = row.iconsrc;
        this.fileid = row.id;
        this.assetsid = row.id;
        this.activerow = row;
      }

    }
© www.soinside.com 2019 - 2024. All rights reserved.