實現思路很簡單:就是利用路由的導購守衛beforeEach在每次頁面跳轉前更改對應的title
第一步:首先在route里面給每個路由加上meta屬性
第二步:在main.js里面加上導航守衛
router.beforeEach((to, from, next) => {
window.document.title = to.meta.title == undefined?'默認標題':to.meta.title
if (to.meta.requireAuth) {
let token = Cookies.get('access_token');
let anonymous = Cookies.get('user_name');
if (token) {
next({
path: '/login',
query: {
redirect: to.fullPath
}
})
}
}
next();
})