usePageContext.ts 562 B

123456789101112131415161718
  1. import type { InjectionKey, ComputedRef, Ref } from 'vue';
  2. import { createContext, useContext } from '/@/hooks/core/useContext';
  3. export interface PageContextProps {
  4. contentHeight: ComputedRef<number>;
  5. pageHeight: Ref<number>;
  6. setPageHeight: (height: number) => Promise<void>;
  7. }
  8. const key: InjectionKey<PageContextProps> = Symbol();
  9. export function createPageContext(context: PageContextProps) {
  10. return createContext<PageContextProps>(context, key, { native: true });
  11. }
  12. export function usePageContext() {
  13. return useContext<PageContextProps>(key);
  14. }