25.传递参数的方式区别

传递参数主要有两种类型:params和query

1.params的类型:

配置路由格式 /router/:id

传递的方式:在path后面跟上对应的值

传递后形成的路径:/router/123, /router/abc

   1.定义数据
   data(){
    return {
      userId:'zhangsan',
    }
  },
2.
<router-link :to="'/user/'+userId" tag="button" replace>用户</router-link>
 或者  
  userClick(){
      this.$router.push('/user/'+this.userId)
   },
​

2.query的类型

配置路由格式:/router,也就是普通配置

传递的方式:对象中使用query的Key作为传递方式

传递后形成的路径:/router?id=123,/router?id=abc/

使用方式<router-link>和JavaScript代码方式

    profileClick(){
      this.$router.push({
        path:'/profile',
        query:{
          name:'kobe',
          age:19,
          height:177
        }
      })
    }

 

posted @ 2021-07-01 13:58  ajaXJson  阅读(104)  评论(0编辑  收藏  举报