路由跳转 携带参数方式

时间:2025-04-08 11:47:48

第一种方式 params传参

原页面内容
gto(index){
      this.$router.push({
          name: 'name',
          params:{
              index
          }
      })
  },
跳转页面接收数据
index: this.$route.params.index,

最终重要的一步

写在router中的内容
{ 
    path: '/group/name',
    name: 'name',
    component: name,
    meta: {
        keepAlive: false, // 不需要缓存当前页面
        rank: 1,
        attribution: 'Teacher_classification' // 归属父级页面
    }
},
这样跳转到的路径就不会显示出传递的参数
http://122.16.34.137:8015/#/group/name

第二种方式 query 传参

原页面内容
this.$router.push({
     path:'/group/name',
     query:{
         index
 }})
跳转页面接收参数
this.$route.query.index
写在router中的内容
{ 
    path: '/group/name',
    name: 'name',
    component: name,
    meta: {
        keepAlive: false, // 不需要缓存当前页面
        rank: 1,
        attribution: 'Teacher_classification' // 归属父级页面
    }
},
这样跳转到的路径就会显示出传递的参数
http://122.16.34.137:8015/#/group/name?index=21bc80108cf04417a3f9f47d50115f83