打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Vue系列:通过vue
使用vue-router 来实现webapp的页面跳转,有时候需要传递参数,做法如下:

主要有以下几个步骤:
(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);
    }


————完————





本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
react路由
vue路由传参
vue $router.push
javascript-从React应用程序中的商店更改路线
初探 React Router 4.0
「原创」图解 React-router 带你深入理解路由本质
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服