traxxx-web/renderer/usePageContext.js

24 lines
616 B
JavaScript
Raw Normal View History

// `usePageContext` allows us to access `pageContext` in any Vue component.
// See https://vike.dev/pageContext-anywhere
2024-03-21 01:54:05 +00:00
import { inject } from 'vue';
2024-03-21 01:54:05 +00:00
const key = Symbol(); // eslint-disable-line symbol-description
let localPageContext = null; // eslint-disable-line import/no-mutable-exports
2024-03-21 01:54:05 +00:00
export function usePageContext() {
const pageContext = inject(key);
return pageContext;
}
export function getPageContext() {
return localPageContext;
}
2024-03-21 01:54:05 +00:00
export function setPageContext(app, pageContext) {
localPageContext = pageContext;
2024-03-21 01:54:05 +00:00
app.provide(key, pageContext);
}
export { localPageContext as pageContext };