四、Vue学習ノート——ルーティング・フックを使ってWebページの名前を動的に変更する


  • はrouterにあります.jsでmeta属性
  • を設定する
    //   
            {
         
              path: "index",
              component: () => import("../views/home/index/index.vue"),
              meta: {
          title: "-  " },
            },
    
  • routerのフックbeforEachでWebページ名
  • を変更
    router.beforeEach((to, from, next) => {
         
      document.title = "XX      " + to.meta.title;
      next();
    });