vue路由带参跳转,刷新后参数不消失

方法一:$router里使用query对象

路由带参数跳转

this.$router.push({
                        name: 'IcProjectView',//跳转的路由(路由的name)
                        params: {//params
                          id: params.row.id,
                          CURD: {
                            value: 'read', readonly: true, disabled: true, visiable: false,
                          },
                        },
                        query:{value: 'read', readonly: true, disabled: true, visiable: false}//query对象,跳转到新路由,然后刷新页面,能继续获取到query 对象
                      })	
刷新页面获取query对象

created() {
      if(this.$route.params.CURD!=undefined){
        this.CURD.value = this.$route.params.CURD.value;
        this.CURD.readonly = this.$route.params.CURD.readonly;
        this.CURD.disabled = this.$route.params.CURD.disabled;
        this.CURD.visiable = this.$route.params.CURD.visiable;
      }else{
        this.CURD.value = this.$route.query.value;
        this.CURD.readonly = this.$route.query.readonly;
        this.CURD.disabled = this.$route.query.disabled;
        this.CURD.visiable = this.$route.query.visiable;
      }
}

这样你的 url 就会像 http://xxx.xxx.xxx/value?value='read',这样无论你怎么刷新 value都不会丢失,参考https://router.vuejs.org/zh-cn/essentials/named-routes.htmlVue-router 命名路由

ps:

router-link

  • 在HTML5 history模式下使用了base选项,所有to属性可以不用写基路径
  • 会拦击点击事件,不会重新加载页面.
  • router-link默认渲染为a标签,我们可以通过tag属性设置为别的标签(常用的li).
  • to属性可以绑定name(命名组件),query(带查询参数)

<router-link :to="{name:'entityList', query:{page: 'Ecp.SystemMessage.List.vdp'}}"
 class="msg" tag="li">

</router-link>//放在需要跳转的标签内

方法二:$router里使用params对象
this.$router.push({name:'articleDetail, params:{articleId: articleId}}); 跳转,那么在路由里就要这样写

routes: [
    {
      path: '/articleDetail/:articleId',
      name: 'articleDetail'
    }
  ]
path: '/articleDetail/:articleId', 里的 :articleId 是必须要有的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值