docs: example using useMeta with definePageMeta (#3552)

This commit is contained in:
Christian Burkhart 2022-03-08 10:02:10 -08:00 committed by GitHub
parent 0f2cba5b1d
commit cbb2e9ce2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -58,3 +58,29 @@ export default {
}
</script>
```
## Example: usage with definePageMeta
You can use `definePageMeta` along with `useMeta` to set metadata based on the current route.
For example, to include the page title alongside your app name, first define your page title:
```vue{}[pages/some-page.vue]
<script setup>
definePageMeta({
title: 'Some Page'
})
</script>
```
And then in your layout file:
```vue{}[layouts/default.vue]
<script setup>
const route = useRoute()
useMeta({
title: computed(() => `App Name - ${route.meta.title}`)
})
</script>
```