vue实现动态改变titlevue
想要实现vue动态改变页面title,须要给每一个页面设置标题。而且在路由发生变化时修改页面titlespa
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
import router from './router' router.beforeEach((to, from, next) => { /* 路由发生变化修改页面title */ if (to.meta.title) { document.title = to.meta.title } next() })