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:
@ -1,7 +1,7 @@
|
||||
import useAppTitle from './useAppTitle';
|
||||
import useCreateContext from './useCreateContext';
|
||||
import useContext from './useContext';
|
||||
import useRouterChange from './useRouterChange';
|
||||
import useRouteParam from './useRouteParam';
|
||||
import useRouteQuery from './useRouteQuery';
|
||||
|
||||
export { useAppTitle, useCreateContext, useRouterChange, useRouteParam, useRouteQuery };
|
||||
export { useAppTitle, useContext, useRouterChange, useRouteParam, useRouteQuery };
|
||||
|
20
src/hooks/common/useContext.ts
Normal file
20
src/hooks/common/useContext.ts
Normal file
@ -0,0 +1,20 @@
|
||||
import { provide, inject } from 'vue';
|
||||
import type { InjectionKey } from 'vue';
|
||||
|
||||
/** 创建共享上下文状态 */
|
||||
export default function useContext<T>(contextName: string = 'context') {
|
||||
const injectKey: InjectionKey<T> = Symbol(contextName);
|
||||
|
||||
function useProvide(context: T) {
|
||||
provide(injectKey, context);
|
||||
}
|
||||
|
||||
function useInject() {
|
||||
return inject(injectKey)!;
|
||||
}
|
||||
|
||||
return {
|
||||
useProvide,
|
||||
useInject
|
||||
};
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
import { provide, inject } from 'vue';
|
||||
import type { InjectionKey } from 'vue';
|
||||
|
||||
/** 创建共享上下文状态 */
|
||||
export default function useCreateContext<T>(contextName: string = 'context') {
|
||||
const injectKey: InjectionKey<T> = Symbol(contextName);
|
||||
|
||||
function useProvider(shareState: T) {
|
||||
provide(injectKey, shareState);
|
||||
}
|
||||
|
||||
function useContext() {
|
||||
return inject(injectKey);
|
||||
}
|
||||
|
||||
return {
|
||||
useProvider,
|
||||
useContext
|
||||
};
|
||||
}
|
@ -1,2 +1,2 @@
|
||||
export { useAppTitle, useCreateContext, useRouterChange, useRouteParam, useRouteQuery } from './common';
|
||||
export { useAppTitle, useContext, useRouterChange, useRouteParam, useRouteQuery } from './common';
|
||||
export { useCountDown, useSmsCode } from './business';
|
||||
|
Reference in New Issue
Block a user