Answer the question
In order to leave comments, you need to log in
How to properly designate Title for dynamic pages in VueJS?
// Router
{
path: '/user/:id',
name: 'User',
component: User,
meta: { title: ЗДЕСЬ НУЖНО ОБОЗНАЧИТЬ ID пользователя }
}
// App.vue
import Menu from './components/Menu'
export default {
name: 'Artefact',
components: {
Menu
},
computed: {
pageTitle() { return this.$route.meta.title; }
},
watch: {
pageTitle: (val) => {
document.title = val;
}
}, created() {
document.title = this.$route.meta.title;
}
}
Answer the question
In order to leave comments, you need to log in
Why not use router.beforeEach
This will save you the competed i from watch
https://router.vuejs.org/ru/guide/advanced/navigat...
// App.vue
import Menu from './components/Menu'
export default {
name: 'Artefact',
components: {
Menu
},
methods: {
getPost() {
fetch('db.json')
.then(res => res.json())
.then(users=> {
document.title = `user ${users.id}`;
.......
})
}
},
created() {
this.getPost()
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question