Vue系列:通过vue-router如何传递参数
来源:互联网 发布:sql查询多字段重复 编辑:程序博客网 时间:2024/06/09 21:00
使用vue-router 来实现webapp的页面跳转,有时候需要传递参数,做法如下:
参考文献:http://router.vuejs.org/en/named.html
主要有以下几个步骤:
(1) 设置好路由配置
router.map({ '/history/:deviceId/:dataId': { name: '
history', // give the route a name
component: { ... } }})
这里有2个关键点:
a)给该路由命名,也就是上文中的 name: 'history',
b)在路径中要使用在路径中使用冒号开头的数字来接受参数,也就是上文中的 :deviceId, :dataId;
(2)在v-link中传递参数;
<a v-link="{ name: '
history', params: { deviceId: 123, dataId:456 }}">history</a>
这里的123,456都可以改用变量。
比如该template所对应的组件有2个变量定义如下:
data: function() {
return {
deviceId:123,
dataId:456
}
}
此时上面那个v-link可以改写为:
<a v-link="{ name: '
history', params: { deviceId: deviceId, dataId: dataId }}">history</a>
(3)在router的目标组件上获取入参
比如在router目标组件的ready函数中可以这么使用。
ready: function(){
console.log('deviceid: ' + this.$route.params.deviceId);
console.log('dataId: ' + this.$route.params.dataId);
}
————完————
阅读全文
0 0
- Vue系列:通过vue-router如何传递参数
- vue-router传递参数
- Vue router 参数传递
- Vue-router props 如何传递参数 ,传参请看这里
- vue-router中参数传递 && 编程式导航 && 坑 && beforeRouteEnter
- vue-router中参数传递 + 编程式导航 + beforeRouteEnter
- vue-router
- vue-router
- vue-router
- vue-router
- Vue router
- vue-router
- vue-router
- vue-router
- vue-router
- vue-router
- vue-router
- vue-router
- Prometheus 监控 Nginx 流量 (三)
- [cvpr2017]Mind the Class Weight Bias: Weighted Maximum Mean Discrepancy for Unsupervised DA
- UML的九种图例详解
- Python 边做边学 9.10 数据库操作--实际使用
- Windows中的cmd报错日志输出到txt文件里:用>>log.txt
- Vue系列:通过vue-router如何传递参数
- 基础篇七---vim编辑器常用快捷命令
- Unity入门操作_刚体 _012
- 动态规划之换零钱
- background以及float
- linux初学者-iptables篇
- (基础篇)数组函数详解
- Canvas----绘制常用的基本图形
- 数据结构 之 树状数组