只在mounted()里面寫下面的代碼,在進(jìn)入這個頁面前其他頁面是能正常的使用鼠標(biāo)右鍵,復(fù)制文本內(nèi)容和F12,但進(jìn)入當(dāng)前頁后再出來就會影響到其他頁面
所以要做到只控制當(dāng)前頁,我們需要在destroyed()鉤子中把這些禁止重新打開,這樣就能實現(xiàn)該功能了文章來源:http://www.zghlxwxcb.cn/news/detail-717282.html
mounted() {
setTimeout(() => {
if (this.copy_switch == false) {
this.$nextTick(() => {
// 禁用右鍵
document.oncontextmenu = new Function("event.returnValue=false");
// 禁用選擇
document.onselectstart = new Function("event.returnValue=false");
// 禁用F12
document.onkeydown = () => {
if (window.event && window.event.keyCode == 123) {
return false
}
}
});
} else {
this.$nextTick(() => {
// 打開右鍵
document.oncontextmenu = new Function("event.returnValue=true");
// 打開選擇
document.onselectstart = new Function("event.returnValue=true");
// 打開F12
document.onkeydown = () => {
if (window.event && window.event.keyCode == 123) {
return true
}
}
});
}
}, 1000);
}
重新打開文章來源地址http://www.zghlxwxcb.cn/news/detail-717282.html
destroyed() {
document.onkeydown = () => {
if (window.event && window.event.keyCode == 123) {
return true
}
}
document.onselectstart = new Function("event.returnValue=true");
document.oncontextmenu = new Function("event.returnValue=true");
},
到了這里,關(guān)于Vue實現(xiàn)當(dāng)前頁面禁止鼠標(biāo)右鍵,復(fù)制文本內(nèi)容和F12的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!