当先锋百科网

首页 1 2 3 4 5 6 7

传值

1:query传值:(path,name都行)

this.$router.push({
        query: { name:'username' },
        name: 'details'
});
this.$router.push({
        query: { name:'username' },
        path: 'details'
});

2:params传值:(只能用name,path不行)

this.$router.push({
        params: { name:'username' },
        name: 'details'
});

3:官网上说的通过new vue()实例来传参的不适用于,路由之间的不同组件之间传参;

获取

 created: function() {
    //   console.log(this.$router)
    //    console.log(this.$router.app)
    //    console.log(this.$router.app._route)
       console.log(this.$route.params.name)
       console.log(this.$route.query.name)
  },

route跟router的区别

this. router.app.route=========this. route

这里写图片描述