added timed refresh
This commit is contained in:
parent
c355bc8f7d
commit
9010b5d81e
|
@ -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(() => {
|
||||
|
|
|
@ -44,10 +44,13 @@ export default {
|
|||
data() {
|
||||
return {
|
||||
tableData: [],
|
||||
updateInterval: null,
|
||||
};
|
||||
},
|
||||
mounted() {
|
||||
this.fetchNodesAndData();
|
||||
|
||||
this.updateInterval = setInterval(this.fetchNodesAndData, 10000)
|
||||
},
|
||||
methods: {
|
||||
async fetchNodesAndData() {
|
||||
|
|
Loading…
Reference in a new issue