vue路由传参几种方法

vue路由传参几种方法

<router-link :to="{path:'/home',query: {name: 123}}">跳转</router-link>
//页面url  /home?name=123
//接收值   this.$route.query.name  

<router-link :to="{path:'/home/:123',}">跳转</router-link>
//页面url  /home/123

<router-link :to="{path:'/home',push: {name: id}}">跳转</router-link>
//接收值 this.$route.params.name  (在页面刷新会消失)


this.$router.push("home");

this.$router.push({ name: 'home', params: { Id: 123 }})
//push里面只能是 name:'xxxx',不能是path:'/xxx',因为params只能用name来引入路由,

this.$router.push(`/home'/${id}`);
//this.$route.params.id 来获取参数
复制代码

router文件中

  {
      path: '/home/:id',
      name: 'home',
      component: resolve => require(['@/components/pages/home'], resolve), // 使用懒加载
    },
复制代码

query 和params的区别

  • query会出现在url上,params不会出现在url上

  • 刷新页面params会小时,query不会消失

转载于:https://juejin.im/post/5c7781b4f265da2da67c41e1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值