added timed refresh
This commit is contained in:
parent
c355bc8f7d
commit
9010b5d81e
|
@ -42,7 +42,7 @@
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { Node, SensorData } from "@/types";
|
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 { key } from "@/store";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ watch([searching, visibleIds], ([searching, visibleIds]) => {
|
||||||
visible.value = searching ? visibleIds.includes(props.node.id) : true;
|
visible.value = searching ? visibleIds.includes(props.node.id) : true;
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
const fetchSensorData = async () => {
|
||||||
try {
|
try {
|
||||||
const { data } = await axios.get<SensorData[]>(
|
const { data } = await axios.get<SensorData[]>(
|
||||||
`http://localhost:8080/api/v1/data?id=${props.node.id}`
|
`http://localhost:8080/api/v1/data?id=${props.node.id}`
|
||||||
|
@ -68,6 +68,14 @@ onMounted(async () => {
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Error fetching sensor data:", error);
|
console.error("Error fetching sensor data:", error);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
fetchSensorData()
|
||||||
|
|
||||||
|
const interval = setInterval(fetchSensorData, 10000)
|
||||||
|
|
||||||
|
onUnmounted(() => clearInterval(interval))
|
||||||
});
|
});
|
||||||
|
|
||||||
const latestSensorData = computed(() => {
|
const latestSensorData = computed(() => {
|
||||||
|
|
|
@ -44,10 +44,13 @@ export default {
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
tableData: [],
|
tableData: [],
|
||||||
|
updateInterval: null,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
this.fetchNodesAndData();
|
this.fetchNodesAndData();
|
||||||
|
|
||||||
|
this.updateInterval = setInterval(this.fetchNodesAndData, 10000)
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async fetchNodesAndData() {
|
async fetchNodesAndData() {
|
||||||
|
|
Loading…
Reference in a new issue