-
Title sums it up. I am extending the page data via a plugin. Let's say I add a new field I want to use the metadata that I've put into // plugin.ts
const myPlugin = {
name: 'myPlugin',
extendsPageData: (page) => {
const meta = 'foobar'
return { meta }
},
};
// Layout.vue
import { usePageData } from '@vuepress/client'
const { value: { meta } } = usePageData()
console.log(meta) // 'foobar'
// enhanceClientApp.ts
import { usePageData } from '@vuepress/client'
// ideally, I'd like to do something like the following, since there's no easy way to do this via any API in VuePress
function generateDynamicTitle(meta) {
if (document) document.title = `${meta} - My Site Name | ${otherMeta.foo}`
}
export default defineClientAppEnhance(({ app, router, siteData }) => {
const { value: { meta } } = usePageData()
console.log(meta) // undefined
generateDynamicTitle(meta)
router.afterEach(() => {
console.log(meta) // 'foobar'
generateDynamicTitle(meta)
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
Oh, I also meet. Because the data is async load. In my mind, the pageData should be tracked, which is only read. |
Beta Was this translation helpful? Give feedback.
-
I commit an issue, but nobody respond. |
Beta Was this translation helpful? Give feedback.
-
There is a previous discussion related to that: #72 |
Beta Was this translation helpful? Give feedback.
There is a previous discussion related to that: #72