子页面加载动画
This commit is contained in:
44
src/App.vue
44
src/App.vue
@@ -1,5 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
|
|
||||||
|
<div v-show="config.loading.subPage" class="loading-bar">
|
||||||
|
<div class="bar-content"></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<el-container>
|
<el-container>
|
||||||
|
|
||||||
<!-- Header -->
|
<!-- Header -->
|
||||||
@@ -50,6 +55,7 @@
|
|||||||
</keep-alive>
|
</keep-alive>
|
||||||
|
|
||||||
</el-container>
|
</el-container>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@@ -104,6 +110,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
watch: {
|
watch: {
|
||||||
|
|
||||||
// 路由名称
|
// 路由名称
|
||||||
'$route.name': {
|
'$route.name': {
|
||||||
handler() {
|
handler() {
|
||||||
@@ -111,6 +118,7 @@ export default {
|
|||||||
this.showHeaderDropdown = false;
|
this.showHeaderDropdown = false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// 更新储存的设置
|
// 更新储存的设置
|
||||||
'config.storage': {
|
'config.storage': {
|
||||||
handler(obj) {
|
handler(obj) {
|
||||||
@@ -122,6 +130,7 @@ export default {
|
|||||||
},
|
},
|
||||||
deep: true
|
deep: true
|
||||||
},
|
},
|
||||||
|
|
||||||
// 改变字体大小
|
// 改变字体大小
|
||||||
'config.storage.fontSize': {
|
'config.storage.fontSize': {
|
||||||
handler(value) {
|
handler(value) {
|
||||||
@@ -133,6 +142,7 @@ export default {
|
|||||||
}, 1000);
|
}, 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
mounted() {
|
mounted() {
|
||||||
var configStr = localStorage.getItem('navConfig');
|
var configStr = localStorage.getItem('navConfig');
|
||||||
@@ -147,6 +157,40 @@ export default {
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="less">
|
<style lang="less">
|
||||||
|
.loading-bar {
|
||||||
|
position: absolute;
|
||||||
|
z-index: 1000;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
height: 0.2rem;
|
||||||
|
|
||||||
|
.bar-content {
|
||||||
|
position: absolute;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 0;
|
||||||
|
height: 100%;
|
||||||
|
background-color: @colorPrimary;
|
||||||
|
animation: loadingBar 4s ease-in-out infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes loadingBar {
|
||||||
|
0% {
|
||||||
|
left: 0;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
50% {
|
||||||
|
left: 0;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
left: 100%;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.main-header {
|
.main-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
|
@@ -1,4 +1,7 @@
|
|||||||
let config = {
|
let config = {
|
||||||
|
loading: {
|
||||||
|
subPage: false
|
||||||
|
},
|
||||||
searchEngines: {
|
searchEngines: {
|
||||||
search: {
|
search: {
|
||||||
title: '搜索',
|
title: '搜索',
|
||||||
|
@@ -2,6 +2,7 @@ import Vue from 'vue';
|
|||||||
import VueRouter from 'vue-router';
|
import VueRouter from 'vue-router';
|
||||||
|
|
||||||
import routes from './routes';
|
import routes from './routes';
|
||||||
|
import config from '../assets/js/config';
|
||||||
|
|
||||||
Vue.use(VueRouter);
|
Vue.use(VueRouter);
|
||||||
|
|
||||||
@@ -9,4 +10,19 @@ const router = new VueRouter({
|
|||||||
routes
|
routes
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// to, from, next
|
||||||
|
router.beforeEach((to, from, next) => {
|
||||||
|
if (to.meta.loadingBar) {
|
||||||
|
config.loading.subPage = true;
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
// to, from
|
||||||
|
router.afterEach((to) => {
|
||||||
|
if (to.meta.loadingBar) {
|
||||||
|
config.loading.subPage = false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
@@ -1,32 +1,42 @@
|
|||||||
import Home from '@/views/Home.vue';
|
|
||||||
|
|
||||||
const routes = [
|
const routes = [
|
||||||
{
|
{
|
||||||
path: '/',
|
|
||||||
name: 'Home',
|
name: 'Home',
|
||||||
component: Home
|
path: '/',
|
||||||
|
meta: {
|
||||||
|
loadingBar: true
|
||||||
|
},
|
||||||
|
component: (resolve) => require(['@/views/Home.vue'], resolve)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/tools',
|
|
||||||
name: 'Tools',
|
name: 'Tools',
|
||||||
component: () => import('@/views/Tools.vue'),
|
path: '/tools',
|
||||||
|
meta: {
|
||||||
|
loadingBar: true
|
||||||
|
},
|
||||||
|
component: (resolve) => require(['@/views/Tools.vue'], resolve),
|
||||||
children: [
|
children: [
|
||||||
{
|
{
|
||||||
path: '/tools/:category/:name',
|
path: '/tools/:category/:name',
|
||||||
name: 'ToolsDetail',
|
name: 'ToolsDetail',
|
||||||
component: () => import('@/views/ToolsDetail.vue')
|
component: (resolve) => require(['@/views/ToolsDetail.vue'], resolve)
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/settings',
|
|
||||||
name: 'Settings',
|
name: 'Settings',
|
||||||
component: () => import('@/views/Settings.vue')
|
path: '/settings',
|
||||||
|
meta: {
|
||||||
|
loadingBar: true
|
||||||
|
},
|
||||||
|
component: (resolve) => require(['@/views/Settings.vue'], resolve)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/about',
|
|
||||||
name: 'About',
|
name: 'About',
|
||||||
component: () => import('@/views/About.vue')
|
path: '/about',
|
||||||
|
meta: {
|
||||||
|
loadingBar: true
|
||||||
|
},
|
||||||
|
component: (resolve) => require(['@/views/About.vue'], resolve)
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user