vue 单页面组件的2种传值方式

来源:互联网 发布:mysql with as 实现 编辑:程序博客网 时间:2024/06/07 15:07

一、路由传值(params:{id:a})

需要传值的组件:

<template>
    <div>
      <router-link :to="{ name: 'twdetails', params: { id: a }}"  >
         
      </router-link>
    </div>
</template>


<script type="text/ecmascript-6">
    export default {
      data(){
        return{
          a:1
        }
      }
    }
</script>


接受值的组件:
<script>
export default {


   data(){
     return{
       id:0
     }
   },
   mounted(){
        console.log('id: ' + this.$route.params.id);
         this.id=this.$route.params.id


   }


}


</script>

this.$route.params用这个得到值




二、this.$router.push("/xxxx?id="+idx)

接收组件xxxx    this.$route.query

原创粉丝点击