vue router路由跳转传参

Quange.vue

<template>
  <div id="Quange">
    <p>{{msg}}</p>
    <button type="button" @click="onClick">跳转</button>
  </div>
</template>

<script>
  export default {
    name: 'Quange',
    data() {
      return {
        msg: 'hello quange!'
      }
    },
    methods: {
      onClick() {
        // 跳转 传参
        this.$router.push({
          path: '/Furong',
          query: {
            id: 1,
            name: 'furong',
            age: 18
          }
        });
        console.log('onClick');
      }
    },
  }
</script>

<style>
  #Quange {
    color: red;
  }
</style>

Furong.vue

<template>
  <div id="Furong">
    <p>{{msg}}</p>
    <p>{{userInfo}}</p>
  </div>
</template>

<script>
  export default {
    name: 'Furong',
    data() {
      return {
        msg: 'hello furong!'
      }
    },
    computed: {
      userInfo() {
        return this.$route.query;
      }
    }
  }
</script>

<style>
  #Furong {
    color: green;
  }
</style>

posted @ 2021-07-08 17:35  thomas_blog  阅读(193)  评论(0编辑  收藏  举报