message sse

This commit is contained in:
jxxghp
2023-07-04 20:21:17 +08:00
parent fd1b774b94
commit 39a2d6c62e
2 changed files with 29 additions and 1 deletions

View File

@@ -1,5 +1,27 @@
<script lang="ts" setup>
import { useToast } from "vue-toast-notification";
import store from "./store";
const route = useRoute();
const $toast = useToast();
onMounted(() => {
const token = store.state.auth.token;
if (token) {
const eventSource = new EventSource(
`${import.meta.env.VITE_API_BASE_URL}system/message?token=${token}`
);
eventSource.addEventListener("message", (event) => {
const message = event.data;
$toast.info(message);
});
onBeforeUnmount(() => {
eventSource.close();
});
}
});
</script>
<template>