博客
关于我
vue中url的跳转以及参数获取
阅读量:492 次
发布时间:2019-03-07

本文共 930 字,大约阅读时间需要 3 分钟。

Vue 页面跳转及 URL 参数获取指南

最近在工作中需要实现两个页面的跳转功能,这对我这个Java小白来说是个新的挑战。我通过百度查找相关知识,尝试在本地进行测试,最终总结出两种可靠的解决方案,记录下来以备后用。

页面跳转方法

在 Vue 中实现页面跳转主要有两种方法:

  • 通过路由别名跳转

    this.$router.push({ name: 'claimApplicationdexAct', query: { accountId1: this.roleFormTemp0.accountId0 } })

    这种方式采用 routeamework 中的 name 属性指定跳转的路径别名,或者也可以使用 path 属性来直接指定目标 URL。使用 query 参数可以在 URL 中公开携带数据,对于需要在 URL 显示部分信息的场景非常有用。如果对参数的隐私性要求更高,可以选择使用 params,这种方式下参数不会被 URL 显示。

  • 通过路由替换跳转

    this.$router.replace('要访问的url')

    这种方法更适合单次跳转或更改当前路由时使用,相比于 push 方法,它不会留下历史记录,但在具体用途中可能会更灵活。

  • 接收路径参数

    在接收路径参数时,可以借助 this.$route.params 来获取携带过来的参数值,与 pushreplace 方法相配套。在路由配置中确保 router 中有占位符支持接收参数,例如:

    路径: ' ruta/*/detalle/'

    这样可以方便地通过 this.$route.paramsันย 获取任意参数,如:

    获取 URL 中的查询参数

    如果需要手动获取 URL 中的查询参数,可以使用以下方法:

    var test = window.location.href;var accountId = test.split("?accountId1=")[1];

    这种方式适用于需要在非 Vue 路由情况下获取 URL 参数,相比于路由参数获取更加灵活,适合处理非路由相关的参数获取。

    作者说明

    我是小宁,一名对技术充满热情的菜鸟开发者,偶尔会分享一些学习心得和工作技巧。如有问题,欢迎留言交流!

    转载地址:http://pbjcz.baihongyu.com/

    你可能感兴趣的文章
    NoSQL&MongoDB
    查看>>
    NoSQL介绍
    查看>>
    Notepad++在线和离线安装JSON格式化插件
    查看>>
    notepad如何自动对齐_notepad++怎么自动排版
    查看>>
    Notification 使用详解(很全
    查看>>
    NotImplementedError: Cannot copy out of meta tensor; no data! Please use torch.nn.Module.to_empty()
    查看>>
    Now trying to drop the old temporary tablespace, the session hangs.
    查看>>
    nowcoder—Beauty of Trees
    查看>>
    np.arange()和np.linspace()绘制logistic回归图像时得到不同的结果?
    查看>>
    npm error MSB3428: 未能加载 Visual C++ 组件“VCBuild.exe”。要解决此问题,1) 安装
    查看>>
    npm install digital envelope routines::unsupported解决方法
    查看>>
    npm install 卡着不动的解决方法
    查看>>
    npm install 报错 EEXIST File exists 的解决方法
    查看>>
    npm install 报错 ERR_SOCKET_TIMEOUT 的解决方法
    查看>>
    npm install 报错 fatal: unable to connect to github.com 的解决方法
    查看>>
    npm install 报错 no such file or directory 的解决方法
    查看>>
    npm install报错,证书验证失败unable to get local issuer certificate
    查看>>
    npm install无法生成node_modules的解决方法
    查看>>
    npm install的--save和--save-dev使用说明
    查看>>
    npm node pm2相关问题
    查看>>