m0_60877809 2021-11-04 16:09 采纳率: 72.7%
浏览 28
已结题

关于vue的路由跳转的问题

如图 点击文字后跳转路由并且高亮了 如何再次点击再次刷新该页面

img

<template>
  <div class="nav-wrap">
    <div v-for="(items, index) in nav" :key="index" class="nav-module">
      <i
        :class="[show[index] ? 'el-icon-arrow-up' : 'el-icon-arrow-down']"
        style="position: absolute; top: 5px; right: 0; cursor: pointer"
        @click="open(index)"
      ></i>
      <div class="nav-title">{{ items.name }}</div>
      <div v-show="show[index]">
        <router-link
          v-for="(item, indexs) in items.child"
          :to="item.path"
          :key="indexs"
          style="text-decoration: none"
        >
          <div class="nav-box" :class="{ selected: selected == item.name }">
            <div
              class="mark"
              :style="{
                background: selected == item.name ? '#FFA500' : '#b3c0d8',
              }"
            ></div>
            {{ item.name }}
          </div>
        </router-link>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  // props:[
  //     'name'
  // ],
  mounted() {
    this.selected = this.$route.meta.name;
    for (let i in this.nav) {
      // debugger
      for (let item in this.nav[i].child) {
        if (this.selected == this.nav[i].child[item].name) {
          this.show[i] = true;
        }
      }
    }
  },
  data() {
    return {
      show: [false, false],
      nav: [
        {
          name: "流动资金贷款",
          child: [
            {
              name: "贷款申请",
              path: "/user/HXapplyForLoans",
            },

            {
              name: "华兴贷款授权",
              path: "/user/HXloanAuthorize",
            },
            {
              name: "华兴贷款列表",
              path: "/user/HXloanList",
            },
          ],
        },
      ],
      selected: "",
    };
  },

  computed: {
    accountType() {
      return this.$store.getters["getterMenuType"];
    },
  },

  methods: {
    open(index) {
      let value = !this.show[index];
      this.$set(this.show, index, value);
    },
  },

  watch: {
    $route: function (newV, oldV) {
      // console.log(newV)
      this.selected = newV.meta.name;
    },
  },
};
</script>


  • 写回答

1条回答 默认 最新

  • pp泉 2021-11-04 17:16
    关注

    你可以绑定一个点击事件

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月13日
  • 已采纳回答 11月5日
  • 创建了问题 11月4日

悬赏问题

  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效