vue動的変更titleの実現
1665 ワード
vue動的変更titleの実現
vueでページtitleを動的に変更するには、各ページにタイトルを設定する必要があります.また、ルーティングが変化した場合にページtitleを変更する
router - index.js
main.js
転載先:https://www.cnblogs.com/DreamerLeaf/p/10875949.html
vueでページtitleを動的に変更するには、各ページにタイトルを設定する必要があります.また、ルーティングが変化した場合にページtitleを変更する
router - index.js
const router = new Router({
mode: 'history',
routes: [
{
path: '/index',
name: 'index',
component: Index,
meta:{
// title
title: ' '
}
},
{
path: '/content',
name: 'content',
component: Content,
meta:{
title: ' '
}
}
]
})
export default router
main.js
import router from './router'
router.beforeEach((to, from, next) => {
/* title */
if (to.meta.title) {
document.title = to.meta.title
}
next()
})
転載先:https://www.cnblogs.com/DreamerLeaf/p/10875949.html