ruoyi-plus-soybean/src/context/app/useReloadContext.ts
2021-09-18 22:17:07 +08:00

37 lines
715 B
TypeScript

import { ref, nextTick } from 'vue';
import type { Ref } from 'vue';
import { useContext } from '@/hooks';
interface ReloadContext {
reload: Ref<boolean>;
handleReload(): void;
}
const { useProvide, useInject: useReloadInject } = useContext<ReloadContext>();
/** 重载上下文 */
export default function useReloadContext() {
const reload = ref(true);
function handleReload() {
reload.value = false;
nextTick(() => {
nextTick(() => {
reload.value = true;
});
});
}
const context: ReloadContext = {
reload,
handleReload
};
function useReloadProvide() {
useProvide(context);
}
return {
context,
useReloadProvide,
useReloadInject
};
}