Я хотел бы знать, как использовать Axios в vueRouter в beforeEach ()
я так и сделал:
router.beforeEach((to, from, next) => {
axios.$http.get('http://localhost:3000/me', {
headers: {
'x-access-token': $cookies.get('user_session') //the token is a variable which holds the token
}
})
.then(response => {
if (response.status == "200") {
console.log('tet3');
}
}, response => {
this.$cookies.remove("user_session");
this.$router.push('/')
//window.location.href = "/";
console.log('erreur', response)
})
if (to.matched.some(record => record.meta.requiresAuth)) {
if (!$cookies.get('user_session')) {
next({
path: '/login',
params: {nextUrl: to.fullPath}
})
} else {
let user = JSON.parse(localStorage.getItem('user'))
if (to.matched.some(record => record.meta.is_admin)) {
if (user.is_admin == 1) {
next()
}
else {
next({name: 'userboard'})
}
}
else {
next()
}
}
} else if (to.matched.some(record => record.meta.guest)) {
if ($cookies.get('user_session') == null) {
next()
}
else {
next({name: 'userboard'})
}
} else {
next()
}
})
и результатом является ошибка:
axios не определено
Я не могу использовать «это», потому что «это» - VueRouter
Вы знаете, как это сделать?
Спасибо