Vue系列vue-router的参数传递的两种方式(五)

前言

在上面的文章当中,小编已经使用过route.params的方式传递参数了,下面我们再来学习一种route.query参数传递的方式。

一、编写Profile页面

在这里插入图片描述

二、编写App.vue入口

普通的写法

<router-link v-bind:to="{path: '/profile',query: {name:'summer-少年',age:18,sex:1,email:'1973984292@qq.com'}}" tag="button" replace>档案</router-link>

当然你也可以这样写

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

触发点击事件

methods: {
    // 参数传递方式
    profileClick(){
        this.$router.push({
            path: '/profile',
            query: {
                name: 'ydf',
                age: 20,
                sex: 2,
                email: '1973984292@qqcom.cn'
            }
        })
    }
}

三、路由配置,index.js

在这里插入图片描述
携带参数:http://localhost:8080/profile?name=ydf&age=20&sex=2&email=1973984292%40qqcom.cn
在这里插入图片描述

四、对比route.params方式传参

路由index.js
在这里插入图片描述
App.vue入口

<router-link v-bind:to="'/user/'+userId+'/name/'+userName" tag="button" replace>用户</router-link>

或者这样写

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

在这里插入图片描述

 // 参数传递方式
userClick(){
    // 带参数跳转
    this.$router.push('/user/' + this.userId+'/name/'+this.userName)
}

页面接受
在这里插入图片描述
在这里插入图片描述

五、项目中

 {
   path: '/dt/detail/:articleId',
    component: Detail
},
@click="detailFun(item.articleId)"
 detailFun(value) {
  this.$router.push(this.articleArray[0].path +'/'+ value)
},
{{$route.params.articleId}}
 created() {
        console.log(this.$route.params.articleId)
    }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

DT辰白

你的鼓励是我创作的源泉

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

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

打赏作者

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

抵扣说明:

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

余额充值