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>
    

      

  • 相关阅读:
    MySQL单实例、多实例服务脚本
    Shell之case结构条件句
    Shell之函数
    Shell之条件测试
    Shell脚本数字比较与四则运算
    Shell之分支结构
    Shell之变量的数值计算与输入
    Shell之变量子串与变量替换
    表单和框架
    HTML部分标签和代码
  • 原文地址:https://www.cnblogs.com/WorldEye/p/13739989.html
Copyright © 2011-2022 走看看