Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
axios.interceptors.request.use(config => {
// 进度条开始
LoadingBar.start();
//token
if (localStorage.getItem('token')) {
config.headers.Authorization = localStorage.getItem('token')
}
return config;
}, error => {
LoadingBar.error();
axios.interceptors.request.use(config => {
// 进度条开始
LoadingBar.start()
// token
if (localStorage.getItem('token')) {
config.headers.Authorization = localStorage.getItem('token')
}
// 防止缓存
if (config.method === 'post' && config.headers['Content-Type'] !== 'multipart/form-data') {
config.data = {
...config.data,
_t: Date.parse(new Date()) / 1000
}
} else if (config.method === 'get') {
config.params = {
_t: Date.parse(new Date()) / 1000,
...config.params
}
}
myRouter.beforeEach((to, from, next) => {
window.aaaa = LoadingBar
LoadingBar.start()
next()
})
myRouter.afterEach((to, from) => {
router.beforeEach(async (to, from, next) => {
LoadingBar.start()
if (getToken()) {
if (to.name === 'login') {
next('/')
} else {
if (store.getters.loggedIn) {
next()
} else {
try {
await store.dispatch('getUser')
} catch (e) {
LoadingBar.error()
return next(false)
}
next()
}
}