element/examples/components/footer-nav.vue

121 lines
2.4 KiB
Vue
Raw Normal View History

2016-09-07 14:18:17 +08:00
<template>
<div class="footer-nav">
<span
v-if="leftNav"
class="footer-nav-link footer-nav-left"
@click="handleNavClick('prev')">
<i class="el-icon-arrow-left"></i>
{{ leftNav.title || leftNav.name }}
</span>
<span
v-if="rightNav"
class="footer-nav-link footer-nav-right"
@click="handleNavClick('next')">
{{ rightNav.title || rightNav.name }}
<i class="el-icon-arrow-right"></i>
</span>
</div>
</template>
<style>
.footer-nav {
padding: 40px 0;
color: #333;
2016-09-07 14:18:17 +08:00
font-size: 14px;
&::after {
content: '';
display: block;
clear: both;
}
& i {
2016-09-07 18:38:51 +08:00
transition: .3s;
color: #999;
2016-09-07 14:18:17 +08:00
vertical-align: baseline;
}
}
.footer-nav-link {
cursor: pointer;
2016-09-07 18:38:51 +08:00
transition: .3s;
2016-09-07 14:18:17 +08:00
&:hover {
color: #409EFF;
2016-09-07 14:18:17 +08:00
& i {
color: #409EFF;
2016-09-07 14:18:17 +08:00
}
}
}
.footer-nav-left {
float: left;
2016-09-21 15:10:27 +08:00
margin-left: -4px;
2016-09-07 14:18:17 +08:00
}
.footer-nav-right {
float: right;
2016-09-21 15:10:27 +08:00
margin-right: -4px;
2016-09-07 14:18:17 +08:00
}
</style>
<script>
import navConfig from '../nav.config.json';
export default {
data() {
return {
currentComponent: null,
nav: [],
currentIndex: -1,
leftNav: null,
rightNav: null
};
},
computed: {
lang() {
return this.$route.meta.lang;
}
},
2016-09-07 14:18:17 +08:00
watch: {
'$route.path'() {
this.setNav();
2016-09-07 14:18:17 +08:00
this.updateNav();
}
},
methods: {
setNav() {
let nav = navConfig[this.lang];
2017-11-01 18:17:14 +08:00
this.nav = [nav[0]].concat(nav[3].children);
nav[4].groups.map(group => group.list).forEach(list => {
this.nav = this.nav.concat(list);
});
},
2016-09-07 14:18:17 +08:00
updateNav() {
this.currentComponent = '/' + this.$route.path.split('/')[3];
2016-09-07 14:18:17 +08:00
for (let i = 0, len = this.nav.length; i < len; i++) {
if (this.nav[i].path === this.currentComponent) {
this.currentIndex = i;
break;
}
}
this.leftNav = this.nav[this.currentIndex - 1];
this.rightNav = this.nav[this.currentIndex + 1];
},
handleNavClick(direction) {
this.$router.push(`/${ this.lang }/component${ direction === 'prev' ? this.leftNav.path : this.rightNav.path }`);
2016-09-07 14:18:17 +08:00
}
},
created() {
this.setNav();
2016-09-07 14:18:17 +08:00
this.updateNav();
}
2016-09-07 18:38:51 +08:00
};
2016-09-07 14:18:17 +08:00
</script>