2023-12-30 05:29:53 +00:00
|
|
|
// `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';
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-03-21 01:54:05 +00:00
|
|
|
const key = Symbol(); // eslint-disable-line symbol-description
|
2024-03-24 03:22:37 +00:00
|
|
|
let localPageContext = null; // eslint-disable-line import/no-mutable-exports
|
2023-12-30 05:29:53 +00:00
|
|
|
|
2024-03-21 01:54:05 +00:00
|
|
|
export function usePageContext() {
|
|
|
|
const pageContext = inject(key);
|
|
|
|
return pageContext;
|
2023-12-30 05:29:53 +00:00
|
|
|
}
|
|
|
|
|
2024-03-24 03:22:37 +00:00
|
|
|
export function getPageContext() {
|
|
|
|
return localPageContext;
|
|
|
|
}
|
|
|
|
|
2024-03-21 01:54:05 +00:00
|
|
|
export function setPageContext(app, pageContext) {
|
2024-03-24 03:22:37 +00:00
|
|
|
localPageContext = pageContext;
|
2024-03-21 01:54:05 +00:00
|
|
|
app.provide(key, pageContext);
|
2023-12-30 05:29:53 +00:00
|
|
|
}
|
2024-03-24 03:22:37 +00:00
|
|
|
|
|
|
|
export { localPageContext as pageContext };
|