18.vue-router传参

使用代码的方式传递:

//路由定义要命名name
{
      path: '/commun',
      name: 'KnowledgeCommun',
      component: KnowledgeCommun,
      children: [
        {
          path: '',
          name: 'RandomLook',
          component: RandomLook
        }, {
          path: 'publish',
          name: 'MyPublish',
          component: MyPublish
        }, {
          path: 'reply',
          name: 'ReplyMe',
          component: ReplyMe
        }, {
          path: 'collect',
          name: 'MyCollect',
          component: MyCollect
        }
      ]
    }
//在父组件中传递userId这个属性,使用名称识别路径
this.$router.push({name: ‘RandomLook’, params: {userId: '123'}});
//子组件中获取参数
//创建页面时获取参数
//是this.$route 不是this.$router
    created() {
      this.getRouterData();
    },
    methods: {
      getRouterData() {
        this.userId = this.$route.params.userId;
      }
    }
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Swift1> Swift和OC的区别1.1> Swift没有地址/指针的概念1.2> 泛型1.3> 类型严谨 对...
    cosWriter阅读 11,161评论 1 32
  • error code(错误代码)=0是操作成功完成。error code(错误代码)=1是功能错误。error c...
    Heikki_阅读 3,462评论 1 9
  • 六年了,说短不短,说长不长。从初识到如今的熟悉,甚至更加亲密,我们经历了很多对于大人们不算什么的坎坷。但总归在...
    雪浓Alyson阅读 587评论 0 5
  • 读写族第四期开班了,族长介绍说这一期藏龙卧虎的人好多,有些人还有公众号什么的,听到这些既喜又怕;我是位读写小白...
    高乐呵阅读 130评论 0 0
  • 我觉得任何成功都是有一定的方法论可探寻的,任何生活窍门都是值得分享的,鼓励身边的朋友和亲人在任何时候都是一种美德。...
    ElingHo期待的美好日常阅读 292评论 0 0