英文:
Is there any way to set meta tags dynamically in nuxt 3?
问题
I'm trying to populate page title and meta tags with dynamic data coming from api for seo purpose. but unable to get it in view-page-source
I've tried useHead, useSeoMeta and useServerSeoMeta with reactive properties. but all these functions called before getting api response. is there any way to get dynamic meta data in view-source-page?
英文:
I'm trying to populate page title and meta tags with dynamic data coming from api for seo purpose. but unable to get it in view-page-source
I've tried useHead, useSeoMeta and useServerSeoMeta with reactive properties. but all these functions called before getting api response. is there any way to get dynamic meta data in view-source-page?
答案1
得分: 6
useSeoMeta
对我来说有效。请注意,值必须是函数。
<script setup>
const id = route.params.id;
const { data: product } = await useAsyncData(id, () =>
apiStore.GET_PRODUCT(id),
);
...
useSeoMeta({
title: () => product.value?.name,
description: () => product.value?.short_description,
ogTitle: () => product.value?.name,
ogDescription: () => product.value?.short_description,
// and other stuff
});
<script>
英文:
useSeoMeta
works for me. Note that values must be functions.
<script setup>
const id = route.params.id;
const { data: product } = await useAsyncData(id, () =>
apiStore.GET_PRODUCT(id),
);
...
useSeoMeta({
title: () => product.value?.name,
description: () => product.value?.short_description,
ogTitle: () => product.value?.name,
ogDescription: () => product.value?.short_description,
// and other stuff
});
<script>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论