我有一些文章有它们各自的元描述。我正在使用vue-meta替换默认的元描述。我尝试使用async和mounted属性从我的API中获取信息,但是我看不到头部的任何变化,即在相应文章的元描述中。我仍然看到Vue js设置的默认值。
这就是我所拥有的:
<script lang="ts">
import { Vue } from 'vue-property-decorator';
import VueMeta from 'vue-meta';
Vue.use(VueMeta);
export default class ArticleContent extends Vue {
article: any | null = null;
articlelist: any = null;
id = 1;
async mounted(): Promise<any> {
this.article = this.articlelist.find((f: any) => { <-- slug
return f.title_slug === this.$route.params.id;
});
this.articlelist = await this.asyncData();
}
async asyncData(): Promise<any> {
const articlelist = await this.$axios.get( <-- call to my api
'https://my_api...'
);
return articlelist.data.data;
}
metaInfo(): any { <-- meta information
return {
title: 'Article',
meta: [
{
hid: this.articlelist[0]._id,
name: this.articlelist[0].productNames['en'],
content: this.articlelist[0].metaDescription['en'],
},
],
};
}
}
</script>我将非常感谢你的帮助,谢谢!
发布于 2019-12-02 20:22:23
您好,您可以使用serverPrefetch而不是使用asyncData
尝尝这个
serverPrefetch():Promise<any> {
// this function should return Promise
return this.$axios.get(
'https://my_api...'
).then(result => {
this.articlelist = result.data.data
});
}https://stackoverflow.com/questions/59136632
复制相似问题