Fork me on GitHub

Vue子组件调用父组件的方法并传值

父组件

<template>
  <div>
    <child @fatherMethod="fatherMethod"></child>
  </div>
</template>
<script>
  import child from '~/components/dam/child';
  export default {
    components: {
      child
    },
    methods: {
      fatherMethod(data) {
        console.log('测试');
      }
    }
  };
</script>

子组件

<template>
  <div>
    <button @click="childMethod()">点击</button>
  </div>
</template>
<script>
  export default {
    methods: {
      childMethod() {
        this.$emit('fatherMethod',data);
      }
    }
  };
</script>

 

posted @ 2021-04-03 20:55  小白不白10  阅读(1266)  评论(0编辑  收藏  举报