vue路由传递参数

1.通过path来确定匹配的路由,通过query来传递参数

传参:

goList(title, id) {
this.$router.push({path: '/list', query: {title: title, id: id}}); //注意这里是 $router
}

接参:

this.params.brandId = this.$route.query.id;//这里是 $route

2.通过路由属性name确定匹配路由,通过params传递参数

传参:

 goList(title, id) {
        // this.$router.push({path: '/list/'+id+"/"+title});//也行
        this.$router.push({name: 'list',params:{"title":title,"id":id}});
      } //传递的参数如果不在路由上进行配置,不会再URL明文显示,但是页面刷新后参数丢失
        //配置如下


router的index.js

 {
      path: '/list/:id/:title',
      name:"list",          //这里需要配置name属性
      component: List,
      meta:{
        title:'列表'
      }
    },

接参:

  this.params.brandId = this.$route.params.id;//这里是 $route,接受字段由query换成params

猜你喜欢

转载自blog.csdn.net/weixin_42315964/article/details/83586395