【发布时间】:2022-01-23 07:27:36
【问题描述】:
这个问题我有一段时间了。 我们有一个在 SSR 模式下运行的 nuxt 网站,其中有一个遵循以下结构的新闻页面:
/pages
/noticia
/_slug
/_id
index.vue
当我们尝试在 Facebook 或任何其他使用 OG:tags 而不是 twitter 的社交媒体上分享它时,就会出现问题,因为 twitter 运行良好。
示例:https://www2.oabrs.org.br/noticia/comunicado-csa/60613 如果您检查上面的链接,您会看到正确的元标签,但在 Facebook 调试器上,它会显示来自另一个新闻的标签。我试图改变蛞蝓,所以它会( /noticia/_id/_slug )但它也没有工作。
索引.vue
head() {
if(this.noticia){
// console.log(this.noticia)
return {
title: decode(this.noticia.titulo),
link: [
{
hid: 'canonical',
rel: 'canonical',
href: `${this.$config.VUE_APP_BASE_HREF + this.$router.currentRoute.fullPath}`
}
],
meta: [
{
hid: "keywords",
property: "keywords",
content: this.noticia.tags,
},
{
hid: "og:url",
property: "og:url",
content: this.$config.VUE_APP_BASE_HREF + this.$router.currentRoute.fullPath,
},
{
hid: "og:title",
property: "og:title",
content: decode(this.noticia.titulo),
},
{
hid: "og:description",
property: "og:description",
content: decode(this.noticia.titulo),
},
{
hid: "og:image",
property: "og:image",
content: this.filename || this.$config.VUE_APP_IMAGES_DEFAULT,
},
{
hid: "twitter:url",
name: "twitter:url",
content: this.$config.VUE_APP_BASE_HREF + this.$router.currentRoute.fullPath,
},
{
hid: "twitter:title",
name: "twitter:title",
content: decode(this.noticia.titulo),
},
{
hid: "twitter:image",
name: "twitter:image",
content: this.filename || this.$config.VUE_APP_IMAGES_DEFAULT,
},
]
};
} else {
return {
title: "Notícia não encontrada",
link: [
{
hid: 'canonical',
rel: 'canonical',
href: `${this.$config.VUE_APP_BASE_HREF + this.$router.currentRoute.fullPath}`
}
],
};
}
},
async asyncData({ app, params, store, route }){
// console.log(route)
try{
await store.dispatch('noticias/fetchNoticia', route.params.id);
// console.log(store.getters['noticias/getNoticia']);
return {
noticia: store.getters['noticias/getNoticia']
}
} catch (e){
// console.log(e)
}
},
我以为它与元字符集有关,但它设置为 UTF-8,所以我猜不是。
【问题讨论】:
标签: vue.js nuxt.js metadata facebook-opengraph meta-tags