通过router-link进行跳转

1.只跳转不传参

  1. <router-link to="/home">
  2. <button>home</button>
  3. </router-link>

2.使用query传递参数,路由必须使用path引入(带查询参数)

  1. <router-link :to="{path: '/home',query: {key: 'hello', value: 'world'}}">
  2. <button>home</button>
  3. </router-link>
  • 跳转地址:/home?key=hello&value=world
  • [x] 跳转之后的页面取值:this.$route.query.key

    3.使用params传递参数,路由必须使用name引入(跳转路由就为/name

    1. <router-link :to="{name: '/home',params: {key: 'hello', value: 'world'}}">
    2. <button>home</button>
    3. </router-link>
  • [x] 跳转地址:/home

  • 取值:this.$route.params.key