其他分享
首页 > 其他分享> > vue路由传参(一看就懂)

vue路由传参(一看就懂)

作者:互联网

 query传参

 this.$router.push({
        path,
        query: {
          userprofile: this.userprofile,
        },
      });

路由里这样配置

{
        path: '/userpage',
        component: UserPage,
        props(route) {
          return {
            userprofile: route.query.userprofile
          }
        }
      }

params传参

必须使用name命名路由组件 

 {
        name: 'recommend',
        path: '/songsheet:id',
        component: SongSheet,
        props(route) {
          return {
            id: route.params.id
          }
        }
      },
 this.$router.push({
        name:'recommend'
        params: {
          userprofile: this.userprofile,
        },
      });

接收参数:在组件里props:['xxx']

标签:传参,vue,route,params,query,id,路由,userprofile
来源: https://blog.csdn.net/jingkai0714/article/details/120969124