vue 父组件调用子组件的函数

子组件

<template>
  <div>
    child
  </div>
</template>
 
<script>
  export default {
    name: "child",
    props: "someprops",
    methods: {
      childFunction(e) {
        console.log(e,"ying")
      }
    }
  }
</script>

 

父组件

<template>
  <div>
    <button @click="clickParent">点击</button>
    <child ref="mychild"></child>
  </div>
</template>
 
<script>
  import Child from './child';
  export default {
    name: "parent",
    components: {
      child: Child
    },
    methods: {
      clickParent() {
        this.$refs.mychild.childFunction("父组件调用");//过this.$refs.ref.method调用
      }
    }
  }
</script>

  

 

posted @ 2018-08-21 16:46  雨筠  阅读(371)  评论(0编辑  收藏  举报