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

View 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
};
}