【VUE】页面A点击后携带参数跳转到页面B并搜索

页面A点击后获取搜索参数,如 ID、Num等,跳转到B页面,使用A页面携带过来的参数在B页面进行搜索。

A页面

html部分

              <template>
                <div
                  @click="getParams(scope.row)"
                >
                  点击跳转
                </div>
              </template>

JS部分

  methods: {
    getParams(row) {
      this.$router.push({
        path: '/B页面路径/',
        query: { id: row.id},
      });
      console.log(row.id, 'row.id');
      console.log(this.$route.query.id, 'this.$route.query.id');
    }
}

B页面

B页面要同时使用watch和activated属性进行操作

如果只添加watch,那么第一次跳转到B页面时参数不会携带并使用携带的参数搜索

  watch: {
    '$route.query.id'(val) {
      if (val) {
        this.queryParams.id= val;
        this.handleQuery();
      }
    },
  },
methods:{
  activated() {
    if (this.$route.query.id) {
      this.queryParams.id= this.$route.query.id;
    }
    this.handleQuery();
  },
}

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值