Небольшие переделки маршрутизации, рефакторинг
This commit is contained in:
@@ -36,7 +36,9 @@
|
||||
</el-aside>
|
||||
|
||||
<el-main>
|
||||
<router-view></router-view>
|
||||
<keep-alive>
|
||||
<router-view></router-view>
|
||||
</keep-alive>
|
||||
</el-main>
|
||||
</el-container>
|
||||
</template>
|
||||
|
||||
@@ -18,6 +18,7 @@ import Vue from 'vue';
|
||||
import Component from 'vue-class-component';
|
||||
import _ from 'lodash';
|
||||
|
||||
const rootRoute = '/cardindex';
|
||||
const tab2Route = [
|
||||
'/cardindex/search',
|
||||
'/cardindex/card',
|
||||
@@ -30,10 +31,7 @@ export default @Component({
|
||||
watch: {
|
||||
selectedTab: function(newValue, oldValue) {
|
||||
lastActiveTab = newValue;
|
||||
const t = Number(newValue);
|
||||
if (tab2Route[t] !== this.curRoute) {
|
||||
this.$router.replace(tab2Route[t]);
|
||||
}
|
||||
this.setRouteByTab(newValue);
|
||||
},
|
||||
curRoute: function(newValue, oldValue) {
|
||||
this.setTabByRoute(newValue);
|
||||
@@ -45,14 +43,23 @@ class CardIndex extends Vue {
|
||||
|
||||
mounted() {
|
||||
this.setTabByRoute(this.curRoute);
|
||||
if (lastActiveTab !== null)
|
||||
this.selectedTab = lastActiveTab;
|
||||
}
|
||||
|
||||
setTabByRoute(route) {
|
||||
const t = _.indexOf(tab2Route, route);
|
||||
if (t >= 0 && t !== this.selectedTab) {
|
||||
this.selectedTab = t.toString();
|
||||
if (t >= 0) {
|
||||
if (t !== this.selectedTab)
|
||||
this.selectedTab = t.toString();
|
||||
} else {
|
||||
if (route == rootRoute && lastActiveTab !== null)
|
||||
this.setRouteByTab(lastActiveTab);
|
||||
}
|
||||
}
|
||||
|
||||
setRouteByTab(tab) {
|
||||
const t = Number(tab);
|
||||
if (tab2Route[t] !== this.curRoute) {
|
||||
this.$router.replace(tab2Route[t]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user