feat(projects): 添加reload context

This commit is contained in:
Soybean
2021-09-18 22:16:31 +08:00
parent 99adbc5a30
commit 03ebd49c86
17 changed files with 354 additions and 228 deletions

10
src/context/app/index.ts Normal file
View File

@ -0,0 +1,10 @@
import useReloadContext from './useReloadContext';
const { useReloadProvide, useReloadInject } = useReloadContext();
/** 从App组件注入provide */
function setupAppContext() {
useReloadProvide();
}
export { setupAppContext, useReloadInject };

View File

@ -0,0 +1,36 @@
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
};
}

3
src/context/index.ts Normal file
View File

@ -0,0 +1,3 @@
import { setupAppContext, useReloadInject } from './app';
export { setupAppContext, useReloadInject };

View File