-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to dynamically update "title" and other meta tags? #813
Comments
@yakhyomus |
In vuejs you can't dynamically update meta tags, now i'm using vuejs 2 |
@yakhyomus to dynamic set meta tags we can work like this. <script> import {fetchData} from "../../../store/api"; import {useHead} from "@unhead/vue"; import { ref } from 'vue' export default { name: "BlogsDetail", data() { return { blog_content:[], }; }, setup(){ const metaTitle = ref(''); const metaDescription = ref(''); const metaKeywords = ref(''); const canonical = ref(''); // Use the useHead hook to dynamically update the title and meta tags useHead({ title: metaTitle, meta: [ {name: 'description', content: metaDescription}, {name: 'keywords', content: metaKeywords}, ], link: [ { rel: 'canonical', href: canonical }, ], }); // expose to template and other options API hooks return { metaTitle,metaDescription,metaKeywords,canonical } }, components: { WidgetsBreadcrumbs }, computed: { settings(){ return useSettingsStore().getSettings } }, methods:{ async get_blog_detail(){ try { const resp = await fetchData('blog/'+this.$route.params.slug,'post'); if (resp.status) { this.blog_content= resp.data; this.metaTitle = resp.data.meta_title??resp.data.title; this.metaDescription = resp.data.meta_description??''; this.metaKeywords = resp.data.meta_keywords??''; this.canonical = resp.data.canonical??''; } else { this.$router.push({ name: 'Page404' }); } }catch (error){ this.$root.toaster.warning('Server Error') } }, }, created() { this.get_blog_detail(); }, } </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Vuejs 3 ("vue-meta": "^3.0.0-alpha.8")
On my vue page i'm trying update title like that:
data() { title: 'title' }, setup () { useMeta({ title: this.title }); }, created() { this.title = 'New title' }
ang get:
Cannot read properties of undefined (reading 'title')
How i can fix that? Thank you!
The text was updated successfully, but these errors were encountered: