javascript - vue2.0 realizes that after logging in, all pages do not need to be logged in, and no login is required. The address of any page visited is transferred to the login page. How to achieve this?
大家讲道理
大家讲道理 2017-05-19 10:36:19
0
3
716

vue After logging in, all pages do not need to be logged in, and no login is required. The address of any page accessed is transferred to the login page to implement the idea.
The project uses vue2.0 axios,

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

reply all (3)
小葫芦

Keywords:
Token-based authentication, JWT, axios interceptor

Link:
Reference link

    黄舟

    In the routing configuration, add the route that requires login

    meta: { requiresAuth: true }

    Determine whether the user is logged in in main.js, and jump to the login page if not logged in

    router.beforeEach((to, from, next) => { if (to.matched.some(record => record.meta.requiresAuth)) { //这里判断用户是否登录,我例子中是验证本地存储是否有token if (!localStorage.token) { next({ path: '/login', query: { redirect: to.fullPath } }) } else { next() } } else { next() // 确保一定要调用 next() } })
      曾经蜡笔没有小新

      Save the login status in local storage or cookie or vuex (preferably vuex), and then the rest is similar to the above

        Latest Downloads
        More>
        Web Effects
        Website Source Code
        Website Materials
        Front End Template
        About us Disclaimer Sitemap
        php.cn:Public welfare online PHP training,Help PHP learners grow quickly!