VUE-CLI Project uses Axios to implement login interception

Source: Internet
Author: User
Log in to intercept one. Some pages in a routing interception project require a user to log in before they can be accessed, adding a field to the routing configuration Requireauth
  • In the Router/index.js

    const router = new Router({  routes: [{  //登陆  path:‘/Login‘,  component:Login},{  //用户中心  path:‘/UserCenter‘,  component:UserCenter,  meta: {    requireAuth: true  },}  ]})router.beforeEach((to, from, next) => {  if (to.matched.some(res => res.meta.requireAuth)) {// 判断是否需要登录权限if (localStorage.getItem(‘token‘)) {// 判断是否登录  next()} else {// 没登录则跳转到登录界面  next({    path: ‘/Login‘,    query: {redirect: to.fullPath}  })}  } else {next()  }})export default router
Two, Axios request intercept,

VUE-CLI Project uses Axios to implement login interception

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.