vue三种页面跳转传参方法

1、push方法:

跳转传参:

 

query传参 参数会在链接后面显示
this.$router.push({ path: "/home", query: { id: 1 }, });

params传参 参数不会显示在链接后面
      this.$router.push({
        name: "/home",
        params: { id: 1 },
      });

params传参要用name 不能用path  切记!

接受参数:

this.$route.params 和 this.$route.query
 
 
 
2、window.href 传参
window.location.href = '/home/?id='+1;

 

3、router-link标签跳转传参 

 

    <router-link :to="{name:'home',params:{id:1}}">跳转啦</router-link>

 

如果有更好的方法可以一起分享!

posted @ 2021-03-29 14:29  dells  阅读(1823)  评论(0)    收藏  举报