美文网首页
Vue 子组件调用父组件方法[不参数版]

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

作者: IT_IOS_MAN | 来源:发表于2019-12-25 11:45 被阅读0次

子组件

<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 : 接收

相关文章

  • 2019-03-13

    vue父子组件传值,(父组件向子组件传值用prop ,子组件向父组件传值:子组件调用父组件方法值以参数的方式传递)...

  • 2019-03-13

    vue父子组件传值,(父组件向子组件传值用prop ,子组件向父组件传值:子组件调用父组件方法值以参数的方式传递)...

  • vue.js 核心知识点三

    目录 - 3.1 vue中子组件调用父组件的方法 - 3.2 Vue父组件调用子组件的方法 - 3.3 涉及到组件...

  • react子组件向父组件传值

    将父组件的方法传递给子组件,子组件通过this.props调用传递过来的方法,并带上参数 父组件 子组件 调用传递...

  • Vue子父组件方法互调

    讲干货,不啰嗦,大家在做vue开发过程中经常遇到父组件需要调用子组件方法或者子组件需要调用父组件的方法的情况,现做...

  • vue父子组件

    父组件向子组件传参数 父组件调用子组件方法 在父组件中引用子组件的标签中使用ref定义组件。 在父组件方法中用$r...

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

    子组件 子组件发出 父组件 父组件接收

  • Uni-App 父类和组件互相调用方法和传参

    父组件调用子组件方法 子组件调用父组件方法

  • vue 父组件调用子组件的方法

    父组件可以通过this.$refs调用子组件的方法 父级.vue 子级 child.vue

  • vue的父子组件传值

    1. 子组件editTree向父组件传:调用父组件的方法createClick,data为参数 2.父组件向子组件...

网友评论

      本文标题:Vue 子组件调用父组件方法[不参数版]

      本文链接:https://www.haomeiwen.com/subject/ehccoctx.html