VUE基础知识积累

144 阅读1分钟

1.页面跳转如何传递和接受参数  www.cnblogs.com/sunww/p/112…

A.通过router-link进行跳转,传递方式:

使用query传递参数,路由必须使用path引入,

使用params传递参数,路由必须使用name引入

  跳转

跳转地址 ====> /home?key=hello&value=world

取值 ====> this.$route.query.key

  跳转

  

取值 ====> this.$route.params.key

实际开发params和query简写为 {hello: 'world'}

B.$router方式跳转

this.$router.path({

  path: '/detail',

  query: {

    name: 'admin',

    code: 10021

  }

});

跳转地址 ====> /detail?name=admin&code=10021

取值 ====> this.$route.query.name

this.$router.path({

  name: 'detail',

  params: {

    code: 10021

  }

});

跳转地址 ====> /detail/10021

取值 ====> this.$route.params.code