update
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
|
||||
export function useRefresh(time = 3000, callback) {
|
||||
const refreshState = ref(false);
|
||||
const timer = ref(null);
|
||||
|
||||
function setRefreshState() {
|
||||
timer.value = setInterval(() => {
|
||||
refreshState.value = !refreshState.value;
|
||||
callback();
|
||||
}, time);
|
||||
}
|
||||
|
||||
function stopRefresh() {
|
||||
clearInterval(timer.value);
|
||||
timer.value = null;
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (timer.value != null) {
|
||||
timer.value = null;
|
||||
}
|
||||
setRefreshState();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
stopRefresh();
|
||||
});
|
||||
return {
|
||||
refreshState,
|
||||
stopRefresh,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
export default {
|
||||
//预警
|
||||
};
|
||||
Reference in New Issue
Block a user