設置頁面標題title


由於每個路由頁面的title可能都不一樣,因此使用document.title來進行動態的改變

1.在定義路由頁面的時候,寫入title名稱

const routes = [
  {
    path: "/home",
    name: "home",
    component: () => import("../views/home.vue"),
    meta: {
      title: "首頁",
    },
  },
]

2.在main.js中使用路由守衛中的前置守衛(beforeEach)來實現title的動態改變

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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM