vue中如何动态改变title中的内容


在vue的index.html中这句话是title中的小图标,可以改成自己的图标:
注意:图标的位置必须卸载public静态文件目录下,否则在改变title内容时,图标会消失成为默认的图标。

要想改变title中的内容,需要在路由文件中,加入meta:{titel:‘首页’}
export default new Router({
routes: [
{
path: ‘/’,
name: ‘index’,
component: index,
meta: {
title: ‘首页’
}
},
{
path: ‘/studentInfo’,
name: ‘studentInfo’,
component: studentInfo,
meta: {
title: ‘列表页’
}
}
]
})
设置完title内容,需要用路由拦截在main.js入口文件中进行判断
router.beforeEach((to, from, next) => {
/* 路由发生变化修改页面title */
if (to.meta.title) {
document.title = to.meta.title
}
next()
})

你可能感兴趣的:(web前端,vue)