mirror of
https://github.com/m-xlsea/ruoyi-plus-soybean.git
synced 2025-09-24 07:49:47 +08:00
feat(projects): 添加reload context
This commit is contained in:
10
src/context/app/index.ts
Normal file
10
src/context/app/index.ts
Normal file
@ -0,0 +1,10 @@
|
||||
import useReloadContext from './useReloadContext';
|
||||
|
||||
const { useReloadProvide, useReloadInject } = useReloadContext();
|
||||
|
||||
/** 从App组件注入provide */
|
||||
function setupAppContext() {
|
||||
useReloadProvide();
|
||||
}
|
||||
|
||||
export { setupAppContext, useReloadInject };
|
36
src/context/app/useReloadContext.ts
Normal file
36
src/context/app/useReloadContext.ts
Normal 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
3
src/context/index.ts
Normal file
@ -0,0 +1,3 @@
|
||||
import { setupAppContext, useReloadInject } from './app';
|
||||
|
||||
export { setupAppContext, useReloadInject };
|
0
src/context/part/index.ts
Normal file
0
src/context/part/index.ts
Normal file
Reference in New Issue
Block a user