vue如何监听当前标签页隐藏和显示(标签页切换)

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)
},

你可能感兴趣的:(vue)