vue白名单/强制登录
// 白名单过滤
router.beforeEach((to, from, next) =>{
//不携带token的路由
var white = [ '/','/mi']
if (white.indexOf(to.path) >= 0){
next()
} else {
var token = localStorage.getItem('token')
if (token){
next()
} else {
router.push('/')
}
}
})
// 拦截器请求前
axios.interceptors.request.use(config=>{
console.log('请求前的拦截器:', config)
//如果有token则携带
var token = localStorage.getItem('token')
if (token){
config.headers['token'] = token
}
return config
})
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
if __name__=="__main__":
app.run(host='127.0.0.1',
port=8000,
debug=True)
