props传参简单使用

1.子给父传

子传

<script>
export default {
  data() {
    return {
       drawer: false,
        form: {
          region: '',
          region1:'',
        }
      }
    },
     methods: {
      onSubmit(){
        console.log(this.form)
        //子向父传数据
        this.$emit('onSubmit', this.form)
      },
    
    }
  }

</script>

父接收

<template>
  <div class="output">
//@onSubmit为子组件传的,onSubmit为当前页面用的
   <mainn @onSubmit="onSubmit"></mainn>
  </div>
</template>

<script>
//引入子组件
import mainn from '../components/mainn.vue'
export default {
//注册
 components:{mainn},
 methods: {
//参数data为子传来的参
   onSubmit(data) {
     console.log(data)
   }
 }
}
</script>

2.父给子传

父传

<template>
  <div class="output">
    //:msg="msg"   :msg为传给子组件的属性,msg为父组件data中的msg
   <mainn :msg='msg'></mainn>
  </div>
</template>

export default {
 components:{mainn},
 data() {
   return {
//传的数据
     msg:'szz'
   }
 },

子接受

//接收
export default {
 props:['msg'],
}
//使用
<template>
  <div>{{msg}}
  </div>
</template>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值