vue如何监听当前标签页隐藏和显示(标签页切换)
mounted() {// 添加监听事件document.addEventListener("visibilitychange", this.handleVisiable);},methods: {handleVisiable: function (e) {if (e.target.visibilityState == "visible") {console.log("回到当前tab标签");}
·
mounted() {
// 添加监听事件
document.addEventListener("visibilitychange", this.handleVisiable);
},
methods: {
handleVisiable: function (e) {
if (e.target.visibilityState == "visible") {
console.log("回到当前tab标签");
} else {
console.log("离开当前tab标签");
}
},
},
beforeDestroy() {
document.removeEventListener('visibilitychange', this.handleVisiable)
},
更多推荐
已为社区贡献2条内容
所有评论(0)