Skip to content

Commit

Permalink
feat: do not reconnect if unmounted
Browse files Browse the repository at this point in the history
  • Loading branch information
jiegec committed Jun 22, 2024
1 parent fc78bb0 commit 3f9e37a
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions frontend/src/pages/monitor/[hostname].vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ export default {
this.fetchData();
},
unmounted() {
this.reconnect = false;
this.socket?.close();
this.socket = undefined;
},
data: () => ({
lines: [] as string[],
socket: undefined as WebSocket | undefined,
reconnect: true,
}),
methods: {
fetchData() {
Expand All @@ -36,9 +38,11 @@ export default {
};
this.socket.onclose = (event) => {
// reconnect after 1s
setTimeout(() => {
this.fetchData();
}, 1000);
if (this.reconnect) {
setTimeout(() => {
this.fetchData();
}, 1000);
}
}
},
},
Expand Down

0 comments on commit 3f9e37a

Please sign in to comment.