Vue 子组件调用父组件方法[不参数版]

2019-12-25  本文已影响0人  IT_IOS_MAN

子组件

<template>
  <div>
    <button @click="childEvent()">点击调父组件方法</button>
  </div>
</template>
<script>
  export default {
    methods: {
      childEvent() {
        this.$emit('parent-event');
      }
    }
  };
</script>

子组件发出

this.$emit('parent-event');

$emit: 发出
parent-event : 方法

父组件

<template>
  <div>
    <child @parent-event="parentEvent"></child>
  </div>
</template>
<script>
  import child from './child';
  export default {
    components: {
      child
    },
    methods: {
      parentEvent() {
        console.log('我是父类方法');
      }
    }
  };
</script>

父组件接收

<child @parent-event="parentEvent"></child>
@parent-event : 接收
上一篇 下一篇

猜你喜欢

热点阅读