电量显示走接口请求

This commit is contained in:
kron
2025-10-29 17:26:27 +08:00
parent 7036135d9c
commit f5d5475ee4
11 changed files with 30 additions and 37 deletions

View File

@@ -1,9 +1,19 @@
<script setup>
defineProps({
power: {
type: Number,
default: 0,
},
import { ref, onMounted, onBeforeUnmount } from "vue";
import { getDeviceBatteryAPI } from "@/apis";
const power = ref(0);
const timer = ref(null);
onMounted(async () => {
timer.value = setInterval(async () => {
const data = await getDeviceBatteryAPI();
power.value = data.battery;
}, 1000 * 10);
});
onBeforeUnmount(() => {
clearInterval(timer.value);
});
</script>