分享

Vue路由带参数

 梦想成为的样子 2017-10-19

传参

this.$route.push({path:'/xxx',query:{id:1}});//类似get传参,通过URL传递参数
this.$route.push({path:'/xxx',params:{id:1}});//类似post传参

接收参数

this.$route.query.id
this.$route.params.id

路径参数使用冒号 : 标记。当匹配到一个路由时,参数值会被设置到 this.$route.params,可以在每个组件内使用。

const router = new VueRouter({
  routes: [
    // 动态路径参数 以冒号开头
    { path: '/user/:id', component: User }
  ]
})

接收:

const User = {
  template: '<div>User {{ $route.params.id }}</div>'
}
参考:https://router./zh-cn/essentials/dynamic-matching.html

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多