fix(menu): currentActiveMenu fails after refresh #188

This commit is contained in:
vben 2021-01-15 00:17:33 +08:00
parent 0aeec5e9d7
commit 6d5c49f0a2

View File

@ -58,6 +58,7 @@
emits: ['menuClick'],
setup(props, { emit }) {
const isClickGo = ref(false);
const currentActiveMenu = ref('');
const menuState = reactive<MenuState>({
defaultSelectedKeys: [],
@ -118,10 +119,11 @@
listenerLastChangeTab((route) => {
if (route.name === REDIRECT_NAME) return;
handleMenuChange(route);
const currentActiveMenu = route.meta?.currentActiveMenu;
if (currentActiveMenu) {
menuState.selectedKeys = [currentActiveMenu];
setOpenKeys(currentActiveMenu);
currentActiveMenu.value = route.meta?.currentActiveMenu;
if (unref(currentActiveMenu)) {
menuState.selectedKeys = [unref(currentActiveMenu)];
setOpenKeys(unref(currentActiveMenu));
}
});
@ -153,6 +155,7 @@
}
const path = (route || unref(currentRoute)).path;
setOpenKeys(path);
if (unref(currentActiveMenu)) return;
if (props.isHorizontal && unref(getSplit)) {
const parentPath = await getCurrentParentPath(path);
menuState.selectedKeys = [parentPath];