yangzongzhuan / RuoYi-Vue3

:tada: (RuoYi)官方仓库 基于SpringBoot,Spring Security,JWT,Vue3 & Vite、Element Plus 的前后端分离权限管理系统
http://ruoyi.vip
MIT License
4.82k stars 1.96k forks source link

[Bug]: 移动端界面时,左侧菜单无法显示 #279

Closed JamesY-Jey closed 3 months ago

JamesY-Jey commented 4 months ago

点击切换菜单显示的按钮,调用 Navbar.vue 中的 toggleSideBar方法时,同时触发了 layout/index.vue 中的 sidebar.value.opened watchEffect监听,导致重复close,无法显示菜单 以下修改可正常显示:

+ watch(() => useRoute(), () => {
+   if (device.value === 'mobile' && sidebar.value.opened) {
+     useAppStore().closeSideBar({ withoutAnimation: false })
+   }
+ })

watchEffect(() => {
-  if (device.value === 'mobile' && sidebar.value.opened) {
-    useAppStore().closeSideBar({ withoutAnimation: false })
-  }
  if (width.value - 1 < WIDTH) {
    useAppStore().toggleDevice('mobile')
    useAppStore().closeSideBar({ withoutAnimation: true })
  } else {
    useAppStore().toggleDevice('desktop')
  }
})
jinceon commented 4 months ago

感谢。我也遇到这个问题了。

arm-liang commented 3 months ago

不需要监听多余的路由切换,只需要监听device,就好了

watch(()=> device.value, ()=>{
  if (device.value === 'mobile' && sidebar.value.opened) {
    useAppStore().closeSideBar({ withoutAnimation: false })
  }
},{immediate:true})

点击切换菜单显示的按钮,调用 Navbar.vue 中的 toggleSideBar方法时,同时触发了 layout/index.vue 中的 sidebar.value.opened watchEffect监听,导致重复close,无法显示菜单 以下修改可正常显示:

+ watch(() => useRoute(), () => {
+   if (device.value === 'mobile' && sidebar.value.opened) {
+     useAppStore().closeSideBar({ withoutAnimation: false })
+   }
+ })

watchEffect(() => {
-  if (device.value === 'mobile' && sidebar.value.opened) {
-    useAppStore().closeSideBar({ withoutAnimation: false })
-  }
  if (width.value - 1 < WIDTH) {
    useAppStore().toggleDevice('mobile')
    useAppStore().closeSideBar({ withoutAnimation: true })
  } else {
    useAppStore().toggleDevice('desktop')
  }
})
yangzongzhuan commented 3 months ago

多谢提醒,已修改。