vue动态修改标题

vue动态修改标题

document.title

  // 笨方法
  create() {
    document.title = 'xxx';
  }
  // 推荐写法(Vue-Router的beforeEach拦截)
  ```js
    // router.js
    {
      name: "xxx",
      path: "xxx",
      component: ()=> import("@/component/xxx.vue"),
      meta: {
        title: "xxx"
      }
    }
  // 路由拦截
  router.beforeEach((to, from, next)> {
    to.meta && (document.title = to.meta.title)
  })
posted @ 2022-08-31 11:17  HuangBingQuan  阅读(146)  评论(0编辑  收藏  举报