12345678910111213141516171819202122232425262728 |
- import { isCtrlPress } from '@/utils/keyboard'
- export default ({ app, store, redirect, $cookies }) => {
- app.router.beforeEach((to, from, next) => {
- // 在每次路由跳转的时候进行判断
- if (isCtrlPress()) {
- // 若是 ctrl 按键被按下,则以新窗口打开目标页面
- window.open(to.fullPath)
- // 并阻止当前页面的跳转
- return next(false)
- }
- let token = ''
- // console.log($cookies.get('can-use-cookie'), 'can use cookie')
- // console.log($cookies.get('token'), 'token')
- if ($cookies.get('can-use-cookie')) {
- token = $cookies.get('token')
- }
- if (token) {
- // console.log('set status')
- store.commit('setUserInfo', $cookies.get('user-info'))
- } else {
- // console.log('remove status')
- store.commit('clearUserInfo')
- }
- next()
- })
- }
|