vue链接传参与路由传参
2024-10-19 07:33:18
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.参数名来接受传递过来的值
最新文章
- This build of Sublime Text 2 has expired
- log4net不同logger输出日志
- Java中类的数据成员的初始化顺序
- Android开源项目分类汇总
- 在mysql数据库原有字段后增加新内容
- ArduinoYun的电源插座
- iOS UICollectionView之-(水平滚动)
- 《利用python进行数据分析》读书笔记--第十章 时间序列(三)
- vcf_filter.py
- mac 上的版本控制工具SmartSVN9.0.4(破解版)
- 网页解析不了PHP源代码的解决方法
- gitLab添加ssh key
- react+redux渲染性能优化原理
- NullPointerException
- 4.6Python数据处理篇之Matplotlib系列(六)---plt.hist()与plt.hist2d()直方图
- HTML—xhtml和html5
- 简单web测试流程(转载)
- 思考的乐趣----matrix67数学笔记:最精妙的无字证明
- poj1221
- 安装unity3d多个版本共存
热门文章
- vue.js官方文档 PDF
- noip考前模板大整理
- HDU2186--水
- 《跟我学IDEA》一、下载安装idea,设置背景字体编码,配置JDK
- Nginx的反向代理与负载均衡
- hdu1181 变形课(vector容器+dfs)
- quick-cocos2d-x教程1:在window上创建第一个项目文件夹,并制作helloworld
- 【Android使用Shape绘制虚线,在4.0以上的手机显示实线】解决方式
- Android 防内存泄露handler
- Parcel.js + Vue 2.x 极速零配置打包体验