vue监听页面离开事件
发布时间:2022-10-24 03:04:02 439 相关标签: # git# github
代码已上传至github
github代码地址:https://github.com/Miofly/mio.git
vue监听页面离开事件
可加入变量判断,根据离开次数加入不同的事件
var app = new Vue({
el: '#app',
data() {
},
mounted() {
document.addEventListener('visibilitychange', this.handleVisiable)
},
destroyed() {
document.removeEventListener('visibilitychange', this.handleVisiable)
},
methods: {
handleVisiable(e) { // 监听页面离开事件
if (e.target.visibilityState === 'visible') {
window.location.href = 'http://www.baidu.com'
}
}
}
})
文章来源: https://blog.51cto.com/u_13028258/5753791
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报