VUE修改页面标题

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接: https://blog.csdn.net/a787373009/article/details/102680877

方法1

修改index.html里的标题,修改后所有页面默认标题都将使用这个标题:
代码如下:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0">
    <link type="favicon" rel="shortcut icon" href="./static/robin.ico"/>
    <title>此处填写标题内容!</title>
  </head>
  <body>
    <div id="app"></div>
    <!-- built files will be auto injected -->
  </body>
</html>

方法2

在使用router+document来配置不同url路径下页面的标题,可以使不同的url路径下的页面标题定制化。
配置步骤1:

 {
    path: '/login',
    component: () => import('../pages/user/login'),
    meta:{
      title:'登录页面!'
    }
  },
  {
    path: '/register',
    component: () => import('../pages/user/register'),
    meta:{
      title:'注册页面!'
    }
  },

配置步骤2:

router.beforeEach((to, from, next) => {
  to.meta.title && (document.title = to.meta.title);
  next()
});

方法3

直接在页面里配置document的标题,代码如下:

 mounted() {
   document.title="设置标题名称!"
  }

猜你喜欢

转载自blog.csdn.net/a787373009/article/details/102680877