是否有任何JavaScript方法可以阻止函数工作
我有一个函数,它有一个if语句和一个是否有任何JavaScript方法可以阻止函数工作,javascript,ecmascript-6,vue.js,frontend,Javascript,Ecmascript 6,Vue.js,Frontend,我有一个函数,它有一个if语句和一个onclick函数。我希望当if语句为true时,整个函数不应该工作。 我试过做return-false,但它对我不起作用 showLogo: function(row) { var a = 0; window.onclick = (e => { let element = e.target.className || e.srcElement.className let element1 = e.target || e.srcEl
onclick
函数。我希望当if语句为true时,整个函数不应该工作。
我试过做return-false,但它对我不起作用
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;
}
}
我正在使用vue.js和Ecmascriptuse
return
停止iti的可能重复我已经编辑了我的帖子,请检查我正在使用的完整功能,我已经使用了return,但它没有work@HaroonAslam但是,当您从它返回时,该函数将不再执行。这不是你想要的吗?你试过了吗?是的,但不起作用,因为onclick中的标志没有走出窗口。onclick
函数我使用了alert来查找并在onclick外声明标志,然后尝试我已经做了你所说的事情,取得了一些成就,但在第一次尝试时,它是wokring,不应该这样做,然后它就成功了就像我希望的那样工作,而不是在第二次尝试使用onlick功能后窗口没有打开它工作不正常,但没有工作,我对此进行了一点调整,但没有取得任何进展
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;
}
},
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;
}
}