This commit is contained in:
邹景立 2021-11-30 21:20:48 +08:00
parent 6fa569d5ec
commit af66e03327

View File

@ -1,10 +1,10 @@
;(async () => { ;(async () => {
const options = { const options = {
moduleCache: { moduleCache: {
vue: Vue, vue: Vue, less: less
less: less
}, },
getFile(url) { getFile(url) {
console.log('load.file', url)
return fetch(url).then(res => { return fetch(url).then(res => {
if (res.ok) { if (res.ok) {
return {getContentData: binary => binary ? res.arrayBuffer() : res.text()}; return {getContentData: binary => binary ? res.arrayBuffer() : res.text()};
@ -34,28 +34,35 @@
router.addRoute({path: '/', redirect: '/static/template/pages/one.vue'}); router.addRoute({path: '/', redirect: '/static/template/pages/one.vue'});
// 路由前置处理 // 路由前置处理
let loading = null;
router.beforeEach(function (to, fr, next) { router.beforeEach(function (to, fr, next) {
let name = to.fullPath.replace(/[.\/]+/g, '_'); let name = to.fullPath.replace(/[.\/]+/g, '_');
if (router.hasRoute(name)) { if (router.hasRoute(name)) {
next(); console.log('');
} else { console.log('load.open', to.fullPath)
let loading = ElementPlus.ElLoading.service({ loading = ElementPlus.ElLoading.service({
lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.3)', lock: true, text: 'Loading', background: 'rgba(0, 0, 0, 0.3)',
}); });
next();
} else {
router.addRoute({name: name, path: to.fullPath, component: loadVueFile(to.fullPath)}); router.addRoute({name: name, path: to.fullPath, component: loadVueFile(to.fullPath)});
setTimeout(() => loading.close(), 1000);
next({name: name}); next({name: name});
} }
}); });
// 动态注销路由 // 动态注销路由
router.afterEach(function (to) { router.afterEach(function (to) {
console.log('Route: ', to.name);
let name = to.fullPath.replace(/[.\/]+/g, '_'); let name = to.fullPath.replace(/[.\/]+/g, '_');
if (router.hasRoute(name)) { if (router.hasRoute(name)) {
console.log('Clear: ', name)
router.removeRoute(name) router.removeRoute(name)
} }
if (loading) {
console.log('load.done')
loading.close();
loading = null;
}
}); });
// window.$think = Vue.createApp({ // window.$think = Vue.createApp({