关于vue中带参数的页面之间跳转

客套话不多说,直接进入主题

以我现在的知识,我认为vue中页面之间的跳转都是通过路由router来跳转,即:

this.$router.push({path: '你要跳转的路由路径'})

在跳转中如果传递参数时有两种方法

(1)

this.$router.push({path:'你要跳转的路由路径',query:{paramName:paramValue}})

跳转过去用接收

this.$route.query.paramName

(2)

this.$router.push({name:'你要跳转的路由name',params:{paramName:paramValue})

跳转过去用接收

this.$route.params.paramName

第一种传递有一种缺点就是你所传的参数会跟到url地址栏的后面,跟get请求还有点相似

第二种就不会有这种状况

这里给出案例

路由(router):

{
    path: '/addRole',
    redirect: '/add/addRole',
    component: Layout,
    hidden: true,
    children: [{
      name: 'addRole',//新增角色
      path: '/add/addRole',
      component: () => import('@/views/role/addRole'),
      meta: {title: '新增角色',}
    }]
  }

在该页面跳转,跳转的方法:


      addRow(row) {
        this.$router.push({name: 'addRole', params: {row: row, title: '编辑角色'}})
        //this.$router.push({path: '/addRole', query: {row: row, title: '编辑角色'}})
      }

接收页面接收的方法,这里我写到了创建方法中,页面跳过来就一定会执行该方法:

    created: function () {
         console.log(this.$route.params)
      // console.log(this.$route.query)
    }

over

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 7
    评论
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值