电量显示走接口请求
This commit is contained in:
@@ -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>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user