added timed refresh

This commit is contained in:
mikailkilli 2024-10-15 10:52:06 +02:00
parent c355bc8f7d
commit 9010b5d81e
2 changed files with 13 additions and 2 deletions

View file

@ -42,7 +42,7 @@
<script setup lang="ts">
import { Node, SensorData } from "@/types";
import { ComputedRef, inject, ref, watch, onMounted, computed } from "vue";
import { ComputedRef, inject, ref, watch, onMounted, computed, onUnmounted } from "vue";
import { key } from "@/store";
import axios from "axios";
@ -59,7 +59,7 @@ watch([searching, visibleIds], ([searching, visibleIds]) => {
visible.value = searching ? visibleIds.includes(props.node.id) : true;
});
onMounted(async () => {
const fetchSensorData = async () => {
try {
const { data } = await axios.get<SensorData[]>(
`http://localhost:8080/api/v1/data?id=${props.node.id}`
@ -68,6 +68,14 @@ onMounted(async () => {
} catch (error) {
console.error("Error fetching sensor data:", error);
}
}
onMounted(async () => {
fetchSensorData()
const interval = setInterval(fetchSensorData, 10000)
onUnmounted(() => clearInterval(interval))
});
const latestSensorData = computed(() => {

View file

@ -44,10 +44,13 @@ export default {
data() {
return {
tableData: [],
updateInterval: null,
};
},
mounted() {
this.fetchNodesAndData();
this.updateInterval = setInterval(this.fetchNodesAndData, 10000)
},
methods: {
async fetchNodesAndData() {