vue-router 传递参数

1.Vue传递参数的方式

在这里插入图片描述

query:
传值

    <router-link :to="{path: '/profile',query:{name:'zhangsan',age:18,height:1.88}}" tag="button">档案</router-link>

代码方式:

<button @click="profileClick">档案</button>


profileClick(){
      this.$router.push({
        path: '/profile',
        query: {
          name: '张三',
          age:18,
          height: 1.88
        }
      })
    }

取值

	<h2>{{$route.query.name}}</h2>
    <h2>{{$route.query.age}}</h2>
    <h2>{{$route.query.height}}</h2>

params:

传值

<router-link :to="/user/+userid" tag="button">用户</router-link>

取值

<template>
  <div>
    <h2>我是用户界面</h2>
    <p>我是用户信息,嘿嘿嘿</p>
    <h2> 通过计算属性:{{userId}}</h2>
<!--  直接获取参数  -->
    <h2>{{$route.params.userid}}</h2>
    </div>
</template>

<script>
export default {
  name: "User",
  computed:{
    userId(){
      //$route :拿到处于活跃状态的路由
      console.log(this.$route);
      return this.$route.params.userid
    }
  }
}
</script>

代码方式:

<button @click="userClick">用户</button>

userClick(){
      this.$router.push('/user/'+this.userid)
    }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值