zoukankan      html  css  js  c++  java
  • 解决vue项目刷新后,导航菜单高亮显示的位置不对问题

    <template>
      <div class="menu">
        <div :class="index==menuIndex?'active':'menu-box'" v-for="(item,index) in menu" :key="index" @click="setMenu(index)">
          <router-link :to="item.path"> <span>{{item.name}}</span></router-link>
        </div>
      </div>
    </template>
    
    <script>
    export default {
      data() {
        return {
          menu: [
            {
              name: "水质预报",
              sort: 1,
              path: "/decisionSupport/waterQualityForecast",
            },
            {
              name: "水质评价",
              sort: 2,
              path: "/decisionSupport/graphAssociation",
            },
            {
              name: "防洪预报",
              sort: 3,
              path: "/decisionSupport/floodControlForecast",
            },
            {
              name: "水量调度",
              sort: 4,
              path: "/decisionSupport/waterDispatching",
            },
            // {
            //   name: "产汇流",
            //   sort: 5,
            //   path:  "/decisionSupport/graphAssociationddd",
            // },
            {
              name: "决策分析",
              sort: 6,
              path: "/decisionSupport/decisionAnalysis",
            },
            {
              name: "应急处置",
              sort: 7,
              path: "/decisionSupport/planaking",
            },
            // {
            //   name: "应急处置",
            //   sort: 7,
            //   path: "/",
            //   children: [
            //     {
            //       name: "预案模板",
            //       path: "/decisionSupport/planaking",
            //     },
            //     {
            //       name: "方案制定",
            //       path: "/decisionSupport/planMaking",
            //     },
            //     {
            //       name: "方案执行指挥",
            //       path: "/decisionSupport/planeDelivery",
            //     },
            //   ],
            // },
          ], //菜单数组
          menuIndex: 0, //菜单下标
        };
      },
      // 这里解决刷新高亮位置改变的代码
      mounted(){
        this.menu.some((item,i)=>{
          if(item.path==this.$route.path){
            this.menuIndex = item.sort-1;
          }
        })
      },
    
    
      methods: {
        //菜单选项卡下标切换
        setMenu(params) {
          this.menuIndex = params;
        },
        handleOpen(key, keyPath) {
          console.log(key, keyPath);
        },
        handleClose(key, keyPath) {
          console.log(key, keyPath);
        },
      },
    };
    </script>
    

      

  • 相关阅读:
    第03组 Alpha冲刺(3/4)
    第03组 Alpha冲刺(2/4)
    第03组 Alpha冲刺(1/4)
    课程总结
    第十四周学习总结&实验报告
    第十三周课程总结
    第十二周学习总结
    第十一周课程总结
    第十周课程总结
    第九周课程总结&实验报告(七)
  • 原文地址:https://www.cnblogs.com/WorldEye/p/13739989.html
Copyright © 2011-2022 走看看