vue-router参数传递

通过query传递

 

 

 

使用$route获取query对象

 

 

 

通过代码跳转路由的方式传递参数

<template>
  <div id="app">
    <router-link to="/home" tag="button" >首页</router-link>
    <router-link to="/about" tag="button" >关于</router-link>
    <router-link :to="'/user/'+name" tag="button" >用户</router-link>
    <!-- <router-link :to="{path: '/profile',query: {id: '111',name: '张三'}}" tag="button">档案</router-link> -->
    <button @click="profileClick">档案</button>
    <!-- 相当于占位符 -->
    <router-view></router-view>
  </div>
</template>

<script>
export default {
  name: 'App',
  data(){
    return{
      name: 'zhangsan'
    }
  },
    methods:{
      profileClick(){
        this.$router.push({
          path: '/profile',
          query:{
          name: '张三',
          age: 20
        }
        })
      }
    }
}
</script>

<style>
/* #app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
} */
</style>

  

posted @ 2022-11-19 17:15  Mr_sven  阅读(24)  评论(0编辑  收藏  举报