fix menu active when route error (#9675)

pull/9741/head
baiyaaaaa 2018-02-08 15:14:15 +08:00 committed by GitHub
parent fa55dbae12
commit d32beea1fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 4 deletions

View File

@ -243,7 +243,9 @@
} }
}, },
handleItemClick(item) { handleItemClick(item) {
let { index, indexPath } = item; const { index, indexPath } = item;
const oldActiveIndex = this.activeIndex;
this.activeIndex = item.index; this.activeIndex = item.index;
this.$emit('select', index, indexPath, item); this.$emit('select', index, indexPath, item);
@ -252,7 +254,10 @@
} }
if (this.router) { if (this.router) {
this.routeToItem(item); this.routeToItem(item, error => {
this.activeIndex = oldActiveIndex;
console.error(error);
});
} }
}, },
// //
@ -271,10 +276,10 @@
submenu && this.openMenu(index, submenu.indexPath); submenu && this.openMenu(index, submenu.indexPath);
}); });
}, },
routeToItem(item) { routeToItem(item, onError) {
let route = item.route || item.index; let route = item.route || item.index;
try { try {
this.$router.push(route); this.$router.push(route, () => {}, onError);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }