Vue routing Guard axios request data

vue route guard axios request data
requirement:
before entering the page, axios requests data and, according to judgment, jumps to the corresponding route.

practice:

1beforeRouteEnter 
axiosaxios
2created
3

excuse me: is there any other way?

Mar.22,2021

practice 1 can be found in the router.js import axios instance

other methods:

  1. you can use Router.routes 's beforeEnter (exclusive routing guard)
  2. you can use beforeRouteEnter (guards within components)
  3. call the global beforeResolve guard

clipboard.png

clipboard.png

finally, introduce axios, into router.js and use prototype pointing, because using axios.get directly will report the error of protocol, so use prototype


have you solved it


beforEnter(to, form ,next){
next(vm=>{
vm.$httpAxios.get
})
}

nextvue
Menu