前端白名单过滤

router.beforeEach(((to, from, next) => {
    let white = ['/clogin', '/index', '/']
    if (white.includes(to.path)) {
        next()
    } else {
        let vuelist = localStorage.getItem('vuelist')
        console.log(vuelist)
        if (vuelist) {
            let reslist = JSON.parse(vuelist)
            console.log(reslist)
            let reslist1 = []
            for (let i in reslist) {
                console.log(i)
                reslist1.push(reslist[i]["url"])
            }
            console.log(reslist1)
            if (reslist1.includes(to.path)) {
                next()
            } else {
                alert('没有权限')
                return false;
            }
        }
    }

}))

 

posted @ 2022-03-07 18:55  ztlman12  阅读(195)  评论(0)    收藏  举报