vue修改瀏覽器的標題title


實現思路很簡單:就是利用路由的導購守衛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();

})


免責聲明!

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



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