-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(plugin): create static manifest for client hydration (#162)
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
const staticImageMap = {} | ||
|
||
function updateImageMap () { | ||
if (typeof window.$nuxt !== 'undefined') { | ||
const pageImages = (window.$nuxt as any)._pagePayload?.data?.[0]?._img || {} | ||
Object.assign(staticImageMap, pageImages) | ||
console.log(staticImageMap) | ||
} | ||
} | ||
|
||
export function useStaticImageMap (nuxtContext?) { | ||
// Update on initialization | ||
updateImageMap() | ||
|
||
// Merge new mappings on route change | ||
if (nuxtContext) { | ||
nuxtContext.app.router.afterEach(updateImageMap) | ||
} | ||
|
||
// Make sure manifest is initialized | ||
if ((window as any).onNuxtReady) { | ||
(window as any).onNuxtReady(updateImageMap) | ||
} | ||
|
||
return staticImageMap | ||
} |