当前位置:   article > 正文

vue-router传递参数的几种方式_this.$router.resolve传params

this.$router.resolve传params

1:js点击跳转传参

  1. 参数在链接上显示
  2. this.$router.push({path: '/details', query: {id: 666}});
  3. this.$route.query.id;
  4. 参数不在链接上显示
  5. this.$router.push({ name: 'details', params: { userId: 123 }});
  6. {{this.$route.params.userId}};
  7. 注:采用params在必须要要在路由上配置name,否则undefined
  8. routes: [
  9. {
  10. path: '/details',
  11. name: 'details',
  12. component: resolve => require(['../components/details'], resolve)
  13. }
  14. ]

 

2:html点击跳转传参

  1. <router-link :to="{name:'home', params: {id:1}}">
  2. $route.params.id // html 取参
  3. this.$route.params.id // script 取参
  4. params传参数 (类似post)
  5. 路由配置 path: "/home/:id" 或者 path: "/home:id"
  6. 不配置path ,第一次可请求,刷新页面id会消失
  7. 配置path,刷新页面id会保留
  8. <router-link :to="{name:'home', query: {id:1}}">
  9. $route.query.id // html 取参
  10. query传参数 (类似get,url后面会显示参数)
  11. 路由可不配置

 

3:其他

this.$router.go(n)

向前或者向后跳转n个页面,n可为正整数或负整数。

如this.$router.go(-1)------->返回上一页

 

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/我家自动化/article/detail/338336
推荐阅读
相关标签
  

闽ICP备14008679号