vue路由跳转

1.需求分析

点击A页面的一个卡片,跳转到B页面的对应的tabItem项的页面。
A页面:
在这里插入图片描述
B页面:
在这里插入图片描述

2.源代码

A.vue

//截取的是关键代码
//点击货架卡片的方法
 <div class="warehouse-card"
   @click.stop="enterIntoShelfManagement(item.houseName, item.houseSn)">
   <div class="img">
     <img
       src="../../../assets/imgs/goods.png"
       style="width: 60px;height: 60px;"
     />
   </div>
   <div class="title">{{ $t("lang.cargo") }}</div>
   <div class="subTitle">
     {{ item.goodsCount }}{{ $t("lang.type") }}
   </div>
 </div>

<script>
enterIntoShelfManagement(warehouseName, warehouseSn) {
      this.$router.push({
        path: "/warehouseList/manage",
        query: { warehouseName, warehouseSn,tabItem:'shielf'},
      });
    },
</script>

B.vue

<template>
  <div class="container">
    <div class="container-header">
      <span @click="goBack">{{ $t("lang.warehouse") }}</span>
      <Icon
        link="icon-icon_page_next"
        customStyle="width:14px;height:14px;color:#999;"
      ></Icon>
      <span @click="goBackStock">{{ warehouseName }}</span>
    </div>
    <div class="container-body">
      <div class="warehouse-tab-header">
        <div
          :class="tabItem == 'stock' ? 'isActived' : ''"
          @click="clickTab('stock')"
        >
          {{ $t("lang.stockManage") }}
        </div>
        <span></span>
        <div
          :class="tabItem == 'shielf' ? 'isActived' : ''"
          @click="clickTab('shielf')"
        >
          {{ $t("lang.shielfManage") }}
        </div>
        <span></span>
        <div
          :class="tabItem == 'device' ? 'isActived' : ''"
          @click="clickTab('device')"
        >
          {{ $t("lang.deviceManage") }}
        </div>
      </div>
      <div class="warehouse-tab-content">
        <StockManage
          v-if="tabItem == 'stock'"
          :warehouseSn="warehouseSn"
        ></StockManage>
        <ShelfManage
          v-if="tabItem == 'shielf'"
          :warehouseSn="warehouseSn"
        ></ShelfManage>
        <DeviceManage
          v-if="tabItem == 'device'"
          :warehouseSn="warehouseSn"
        ></DeviceManage>
      </div>
    </div>
  </div>
</template>

<script>
import StockManage from "./stockManage/stockManage.vue";
import ShelfManage from "./shelfManage/shelfManage.vue";
import DeviceManage from "./deviceManage/deviceManage.vue";
// import { threadId } from "worker_threads";

export default {
  components: {
    StockManage,
    ShelfManage,
    DeviceManage
  },
  data() {
    return {
      // tabItem: "stock",
      tabItem: "",
      warehouseSn: "",
      warehouseName: ""
    };
  },
  mounted(){
    console.log("tabItem",this.tabItem)
  },
  created() {
    if (this.$route.query.warehouseName) {
      this.warehouseName = this.$route.query.warehouseName;
    }
    if (this.$route.query.warehouseSn) {
      this.warehouseSn = this.$route.query.warehouseSn;
    }
      if (this.$route.query.tabItem) {
      this.tabItem = this.$route.query.tabItem;
    }

  },
  methods: {
    clickTab(param) {
      this.tabItem = param;
      //   Storage.sessionSet('tabItem', param)
    },
    goBack() {
      this.$router.push("/warehouseList");
    },
    goBackStock() {
      this.tabItem = "stock";
    }
  }
};
</script>
3.思路总结

其实点击不同卡片跳转到同一页面的不同tabItem项下面的页面,其实就是多带一个tabItem参数。
就是这么简单!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序媛夏天

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值