to.matched.some(function (item) {}

router.beforeEach((to, from, next) => {
if (to.matched.some(record => record.meta.requiresAuth)) {

 
  if (!localStorage.token) { 
    next({
      path: '/login',
      query: { redirect: to.fullPath }
    })
  } else {
    next()
  }
} else {
  next() // 确保一定要调用 next()
}

})
to.matched.some(record => record.meta.requiresAuth)这一段什莫意思啊 有大神知道吗

阅读 5.2k
1 个回答

你可以看下 es6的 some方法。 这里的意思是,to.matched 的数组,如果在mate中有requiresAuth 那么就返回true

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进