vue组件传递

这里测试了一个父组件接受子组件的实例

App.vue

import componentA from './components/componentA'
listenToMyBoy:function (msg) {
 this.childworlds=msg
 }
 <p>boy tell me:{{childworlds}}</p>
    <component-a msgformfather='you die!' v-on:child-tell-me-sth='listenToMyBoy'></component-a>

 componentA.vue

<script>
  export default {

    data: function () {
      return {
        msg: 'hello from componentA',
      }
    },
    props:['msgformfather'],
    methods: {
      clickme:function () {
        // console.log(this.msgformfather)

       this.$emit('child-tell-me-sth',this.msg)

        //   this.$dispatch('child-tell-me-sth',this.msg)
      }
    }
  }
</script>

<style>

</style>
childworlds: '' 需要在data属性里面设置,切记

这里使用到的是$emit,然后通过v-on的绑定事件进行监听

已经废弃$dispatch,这边是官方具体文档说明,自己没有试过,/狗头保命

https://cn.vuejs.org/v2/guide/migration.html#dispatch-%E5%92%8C-broadcast-%E6%9B%BF%E6%8D%A2

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值