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>

补充4、利用resolve新打开新窗口传参

  const {href}= this.$router.resolve({
                name:"animation",//要打开的路由name
                query:{
                    id:321 //传递参数
                }
  });
  window.open(href,"_blank") //打开新窗口
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容