diff --git a/App.vue b/App.vue index e865a4e..716b4bf 100644 --- a/App.vue +++ b/App.vue @@ -29,9 +29,9 @@ export default { }, sendHeartbeat() { - Home.online().then((response) => { - console.log('心跳机制'); - }).catch((err) => {}); + Home.online().then((response) => { + console.log('心跳机制'); + }).catch((err) => {}); }, startHeartbeat() { if (!this.heartbeatInterval && this.isLogin) { @@ -171,6 +171,10 @@ export default { mounted() { // 监听页面可见性变化 document.addEventListener('visibilitychange', this.handleVisibilityChange); + // 立即发送一次心跳请求 + if (this.isLogin){ + this.sendHeartbeat() + } // 启动心跳机制 this.startHeartbeat(); },