N
Nuxt2y ago
Timmmy

Refetching data every x minutes

<script setup >

const props = defineProps({
deviceUrl: String
})

const { data: status, pendingStatus, refresh: refreshStatus } = useLazyFetch(props.deviceUrl + "/status")
const { data: settings, pendingSettings, refresh: refreshSettings } = useLazyFetch(props.deviceUrl + "/settings")

function toggleDevice(isOn) {
if (isOn) {
useLazyFetch(props.deviceUrl + "/relay/0?turn=off")
} else {
useLazyFetch(props.deviceUrl + "/relay/0?turn=on")
}

refreshStatus();
refreshSettings();
}

</script>
<script setup >

const props = defineProps({
deviceUrl: String
})

const { data: status, pendingStatus, refresh: refreshStatus } = useLazyFetch(props.deviceUrl + "/status")
const { data: settings, pendingSettings, refresh: refreshSettings } = useLazyFetch(props.deviceUrl + "/settings")

function toggleDevice(isOn) {
if (isOn) {
useLazyFetch(props.deviceUrl + "/relay/0?turn=off")
} else {
useLazyFetch(props.deviceUrl + "/relay/0?turn=on")
}

refreshStatus();
refreshSettings();
}

</script>
I want to automatically update status & settings every minute, how would I do that?
10 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Timmmy
TimmmyOP2y ago
Because the data changes and I want to make sure the data is up to date
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Timmmy
TimmmyOP2y ago
There is no web socket though
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Timmmy
TimmmyOP2y ago
The api is hosted locally on iot devices that measure the amount of energy a specific device is using So unfortunately I will have to do polling
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Timmmy
TimmmyOP2y ago
Alright thank you, I will try that out
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Timmmy
TimmmyOP2y ago
I think I am already doing client side fetching so this shouldnt be an issue I guess + Website will only run locally on a raspberry pi so Thanks for your help @Sr. Full Stack Dev @needmorewood ❤️
Want results from more Discord servers?
Add your server