vue关于父组件调用子组件的方法

用$ref调用 
子组件

<template>
  <div>

  </div>
</template>

<script>
  export default {
    data(){
      return {
        num:'123'
      }
    },
    computed: {
    },
    components: {      
      'children': children
    },
    methods:{
      childMethod() {
        alert('childMethod do...')
      }
    },
    created(){
    }
  }
</script

父组件

父组件: 在子组件中加上ref即可通过this.$refs.ref.method调用
<template>
  <div @click="parentMethod">
    <children ref="map"></children>
  </div>
</template>

<script>
  import children from 'components/children/children.vue'
  export default {
    data(){
      return {
      }
    },
    computed: {
    },
    components: {      
      'children': children
    },
    methods:{
      parentMethod() {
        console.log(this.$refs.map) //返回的是一个vue对象,所以可以直接调用其方法
        this.$refs.map.childMethod(); 
      }
    },
    created(){
    }
  }
</script>
原文地址:https://www.cnblogs.com/zhaoboxing/p/7265114.html