vuejs几种不同组件(页面)间传值的方式

需要注意的是,实用params去传值的时候,在页面刷新时,参数会消失,用query则不会有这个问题。

这样使用起来很方便,但url会变得很长,而且如果不是使用路由跳转的界面无法使用。取值方式分别为:this.$route.params.routeParamsthis.$route.query.routeParams

this.$router.push({
      name: 'login', //跳转页面
      query/params: {
        routeParams: params
      }
})

注:使用params传值,也可以做到页面刷新,参数不丢失,在命名路由时这样设置:

但这样不适合数组和对象

{
      path: '/OrderDetail/:orderId/:type',
      name: 'OrderDetail',
      component: OrderDetail,
      meta: {
        title: '订单详情',
        needAuth: true
      }
}

还有其他三种方法,可参考https://blog.csdn.net/qq_32786873/article/details/70844811

原创文章 181 获赞 19 访问量 3万+

猜你喜欢

转载自blog.csdn.net/Pandora_417/article/details/105663968