window.VUE_ROUTER
window.VUE_ROUTER
全局 VueRouter 实例
import Vue from 'vue';
import routers from '@/routers/index';
import App from '@/views/app.vue';
import store from '@/store/index';
import '@/utils/iconfont.js';
import ElementUI from 'element-ui';
import VueRouter from 'vue-router';
import 'animate.css';
import 'element-ui/lib/theme-chalk/index.css';
import 'element-ui/lib/theme-chalk/display.css';
import 'font-awesome/css/font-awesome.min.css';
import '@/styles/app.scss';
import * as PACKAGE from '../package.json';
// disable vue devtool
Vue.config.productionTip = false;
ElementUI.Dialog.props.closeOnClickModal.default=false;
Vue.use(ElementUI, { size: 'small' });
Vue.use(VueRouter);
const router = new VueRouter({
mode: 'history',
routes: routers,
});
window.VUE_ROUTER = router;
router.beforeEach((to, from, next) => {
const token = UtilCache.getLocalItem('token');
if (!token && to.path !== '/login') {
next({ name: 'Login' });
} else {
next();
}
});
// eslint-disable-next-line no-new
new Vue({
router,
store,
render: h => h(App),
}).$mount('#app');
console.log('🔥 this.$route', this.$route);
console.log('🔥 window.VUE_ROUTER', window.VUE_ROUTER, window.VUE_ROUTER.routes);
✅ OK
refs
©xgqfrms 2012-2020
www.cnblogs.com 发布文章使用:只允许注册用户才可以访问!
原创文章,版权所有©️xgqfrms, 禁止转载 🈲️,侵权必究⚠️!
本文首发于博客园,作者:xgqfrms,原文链接:https://www.cnblogs.com/xgqfrms/p/14744407.html
未经授权禁止转载,违者必究!