Jelajahi Sumber

左侧导航补选中刷新后为定位问题

lihongxiao 3 tahun lalu
induk
melakukan
58a29bd492
2 mengubah file dengan 11 tambahan dan 8 penghapusan
  1. 0 2
      src/router/index.js
  2. 11 6
      src/views/HeadBar/HeadBar.vue

+ 0 - 2
src/router/index.js

@@ -205,8 +205,6 @@ function addDynamicRoutes(menuList = [], routes = []) {
           route['component'] = resolve => require([`@/views/${url}`], resolve)
         } catch (e) { }
       }
-      console.log(route,111111111)
-
       routes.push(route)
     }
   }

+ 11 - 6
src/views/HeadBar/HeadBar.vue

@@ -97,6 +97,7 @@ export default {
       themeColor: state => state.app.themeColor,
       collapse: state => state.app.collapse,
       navTree: state => state.menu.navTree,
+      leftTree: state => state.menu.leftTree,
     }),
     leftNavItems: function () {
       if (this.sum > 0) {
@@ -127,14 +128,13 @@ export default {
     }
   },
   created() {
-
+    if(localStorage.getItem("routerId")){
+        this.$store.commit('changeLeftTree', localStorage.getItem("routerId"));
+      }
     if(!JSON.parse(localStorage.getItem('user_data'))){
       this.$api.user.getLoginUser().then((response) => {
-             this.userData=response.data 
-          })
-    }
-    if(localStorage.getItem("routerId")){
-      this.$store.commit('changeLeftTree', localStorage.getItem("routerId"));
+          this.userData=response.data 
+      })
     }
     if (this.leftNavItems.length > 8) {
       if (this.screenWidth < this.datawidth) {
@@ -153,6 +153,11 @@ export default {
 
   },
   watch: {
+    navTree(newValue){
+      if(localStorage.getItem("routerId") &&  newValue.length>0){
+        this.$store.commit('changeLeftTree', localStorage.getItem("routerId"));
+      }
+    },
     screenWidth(newValue) {
         this.sum = Math.ceil((this.datawidth - newValue) / 70)
         // 为了避免频繁触发resize函数导致页面卡顿,使用定时器