update
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
import { onMounted, onUnmounted, ref } from 'vue';
|
||||
import { isFunction } from '/@/utils/is.ts';
|
||||
|
||||
export function useRefresh(time = 3000, callback) {
|
||||
/**
|
||||
* @desc 定时刷新
|
||||
* @param time
|
||||
* @param callback
|
||||
*/
|
||||
|
||||
export function useRefresh(time = 3000, callback?: Function) {
|
||||
const refreshState = ref(false);
|
||||
const timer = ref(null);
|
||||
|
||||
function setRefreshState() {
|
||||
timer.value = setInterval(() => {
|
||||
refreshState.value = !refreshState.value;
|
||||
callback();
|
||||
}, time);
|
||||
startRefresh();
|
||||
}
|
||||
|
||||
function stopRefresh() {
|
||||
@@ -16,6 +20,15 @@ export function useRefresh(time = 3000, callback) {
|
||||
timer.value = null;
|
||||
}
|
||||
|
||||
function startRefresh() {
|
||||
timer.value = setInterval(() => {
|
||||
refreshState.value = !refreshState.value;
|
||||
if (callback && isFunction(callback)) {
|
||||
callback();
|
||||
}
|
||||
}, time);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
if (timer.value != null) {
|
||||
timer.value = null;
|
||||
@@ -29,5 +42,6 @@ export function useRefresh(time = 3000, callback) {
|
||||
return {
|
||||
refreshState,
|
||||
stopRefresh,
|
||||
startRefresh,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user