vue-router路由参数刷新消失的问题

vue-router路由参数刷新消失的问题

页面使用vue-router在跳转时发的参数有用来给下一个页面请求数据用的。在进入页面后再次刷新,参数就消失了,解决方案如下:
这里写图片描述

1、如果要用 params 传参的话,可能需要在你的路由路径里也加上这个参数,比如你用

this.$router.push({name:'articleDetail, params:{articleId: articleId}});

跳转,那么在路由里就要这样写

routes: [
    {
      path: '/articleDetail/:articleId',
      name: 'articleDetail'
    }
  ]

path: '/articleDetail/:articleId',里的 :articleId 是必须要有的,具体的可以参考 Vue-router 命名路由

2、你在用 vue-router 跳转的时候可以把参数写进 query 里this.$router.push({name:’articleDetail, query:{articleId: articleId}});

this.$router.push({name: 'addGoodsList', query: {title: '添加商品'}})

这样你的 url 就会像 http://xxx.xxx.xxx/articleDetail?articleId=123,这样无论你怎么刷新 articleId 都不会丢失

然后在你的 init 方法里 可以用 this.articleId = this.$route.query.articleId; 来获取id

this.title2 = this.$route.query.title;
  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值