Vue

vue跳转路由

2018-12-07  本文已影响0人  山中经

vue中:

方式一:

传递:
this.$router.push({ path: '', query: {  key: value,key: value  } })
接受: this.$route.query.xxx

方式二(此方法传的的参数不会在url地址栏中显示出来):

传参:
this.$router.push({
      name: '', //此处的name值在路由表中的要跳转至那个页面的name值,也是由于nuxt 中路由表乃自动生成,故nuxt中不能用此方法
      params: { key: 'value, key: 32 }
    })
接收 
this.$route.params.xxx

方式三:
须在路由中配置 { path: '/c/:id', name: 'C',component: C }

传this.$router.push('/c/58') 
接收 this.$route.params.id
传this.$router.push('/c') (注意:这种方式不可取)
接收 this.$route.params.id(此时页面的生命周期不会执行)
传  :this.$router.push({ path: `/c/58`,query: {name: '桐梓' } }) 
接收  this.$route.params.id   this.$route.query.xxx
上一篇下一篇

猜你喜欢

热点阅读