位置:首页 > Vue >

vue设置网页页面title--router

字号+ 作者:micloud 来源:www.seoalphas.com 2020-12-23 08:54 浏览量:2609

新建的vue项目默认情况下页面标题就是项目文件夹的名称,显然这是不合适的,我们可以通过router来处理vue新建项目页面没有标题的情况。

1、路由设置meta,meta中设置title

{
    path: '/',
    name: 'home',
    component: Home,
    meta: {
      // 页面标题title
      title: '标题'
    }
  }


2、路由前置守卫设置

mian.js中设置前置路由守卫。

router.beforeEach((to, from, next) => {
  /* 路由发生变化修改页面title */
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

通过上面两步就可以完成vue页面设置操作。

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • vue点击事件@click.stop(阻止冒泡).native

    vue点击事件@click.stop(阻止冒泡).native

    浏览次数:8918

  • Vue+Element UI Radio默认选中问题 selected

    Vue+Element UI Radio默认选中问题 selected

    浏览次数:7898

  • vue img标签:onerror="defaultImg"或@error=“defImg()” 使用

    vue img标签:onerror="defaultImg"或@error=“defImg()” 使用

    浏览次数:2460

  • vue Element的Dialog组件中使用wangEditor初始化问题

    vue Element的Dialog组件中使用wangEditor初始化问题

    浏览次数:2355

网友点评
评论区域