父组件点击其中一个项带参数(query或者params)跳转到详情页案例

6 篇文章 0 订阅
1 篇文章 0 订阅

父组件

  编号:
      <el-input
        v-model="pageParams.planCode"
        placeholder="请输入编号"
        style="width:200px"
      ></el-input>
 <el-button style="margin-right:10px" plain type="primary" @click="detailFun(row)"
            >查看详情</el-button
          >
 methods: {
    detailFun(item) {
      this.$router.push({
        path: '/emergencyPlan/planDetail',
        query: {
          planCode: item.planCode
        }
      })
    }
   }

点击进入其中一个子组件

 预案编号:
      <el-input v-model="plan.planCode" :disabled="true" style="width:200px"></el-input> 
 data() {
    return {
      plan: []
    }
  }

= this.$route.query.“参数名” (子组件接受语法写在mounted里面)

 mounted() {
    this.plan.planCode = this.$route.query.planCode
    console.log(this.plan.planCode)
    this.detailFun()
  },
  methods: {
    detailFun() {
      let p = {
        planCode: this.plan.planCode
      }
      getPlanInfos(p).then(res => {
        console.log(res.data)
      })
    }
  }

思路详解:

一:
父组件
点击查看详情,需要跳转,1.路径:path
 2. 参数(query/params) 参数就是点击这一项的带的唯一值,序号的id,pageParams.planCode这一项就是。(也看情况需要查的一项,再找对应的参数,id多一点)
二:
点击进入详情页其中一个里面后(子组件):
1.接收通常写在mounted(较为多,一般接口调用都在这里面)或者methods 
接收 用  = this.$router.query.需要传的参数
 mounted() {
    this.plan.planCode = this.$route.query.planCode
  }
等号前面是 data里面的 传到本组件里面
 data() {
    return {
      plan: []
    }
  }
本身是空数组,传过来就可以连接上了  预案编号:<el-input v-model="plan.planCode" :disabled="true" style="width:200px"></el-input>


然后请求数据

methods: {
    detailFun() {
      let p = {
        planCode: this.plan.planCode
      }
      getPlanInfos(p).then(res => {
        console.log(res.data)
      })
    }
  }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值