1、链接传参:

  例如:链接是:http://localhost:3333/#/index?id=001

  我们要获取参数:console.log(this.$route.query.id);即可

2、路由传参:

  (一、显示在url中)

  main.js params传值是通过 :[参数值] 如path: "/home/game/:num"

    例:

{
path: "/home", component: home,
children: [
{ path: "/home/game/:num", component: game }
]
}

  父组件路由跳转写法:

    :to="{path:'/game/'+item.Id}"

  子组件取路由参数:

    通过 this.$route.params.参数名来接受传递过来的值

  (二、不显示在url中):这种方法再刷新页面后参数消失,不建议使用

    只需将上面的main.js中的定义路由改为如下样子,在子路由中通过name来给路径其一个game1的别名。

      

//定义路由
const routes = [
{ path: "/", redirect: "/home" },//重定向
{
path: "/home", component: home,
children: [
{ name: "game1", path: "/home/game/", component: game }
]
}
]

    home.vue 中router-link修改为:to="{ name:'game1', params: {num: 123} }" params中是要传递的参数,这样传递的参数就不会显示在url中。

  

<template>
<div>
<h3>首页</h3>
<router-link :to="{ name:'game1', params: {num: 123} }">
<button>显示</button>
</router-link>
<router-view></router-view>
</div>
</template>

  

 子组件取路由参数:

      通过 this.$route.params.参数名来接受传递过来的值

最新文章

  1. This build of Sublime Text 2 has expired
  2. log4net不同logger输出日志
  3. Java中类的数据成员的初始化顺序
  4. Android开源项目分类汇总
  5. 在mysql数据库原有字段后增加新内容
  6. ArduinoYun的电源插座
  7. iOS UICollectionView之-(水平滚动)
  8. 《利用python进行数据分析》读书笔记--第十章 时间序列(三)
  9. vcf_filter.py
  10. mac 上的版本控制工具SmartSVN9.0.4(破解版)
  11. 网页解析不了PHP源代码的解决方法
  12. gitLab添加ssh key
  13. react+redux渲染性能优化原理
  14. NullPointerException
  15. 4.6Python数据处理篇之Matplotlib系列(六)---plt.hist()与plt.hist2d()直方图
  16. HTML—xhtml和html5
  17. 简单web测试流程(转载)
  18. 思考的乐趣----matrix67数学笔记:最精妙的无字证明
  19. poj1221
  20. 安装unity3d多个版本共存

热门文章

  1. vue.js官方文档 PDF
  2. noip考前模板大整理
  3. HDU2186--水
  4. 《跟我学IDEA》一、下载安装idea,设置背景字体编码,配置JDK
  5. Nginx的反向代理与负载均衡
  6. hdu1181 变形课(vector容器+dfs)
  7. quick-cocos2d-x教程1:在window上创建第一个项目文件夹,并制作helloworld
  8. 【Android使用Shape绘制虚线,在4.0以上的手机显示实线】解决方式
  9. Android 防内存泄露handler
  10. Parcel.js + Vue 2.x 极速零配置打包体验