vue 父组件调用子组件方法

父组件代码

<template>
  <div>
  我是父组件
   <borderTable ref="child"></borderTable>
  </div>
</div>
</template>

<script>

  import borderTable from '../tables/borderTable.vue'
  export default {
    components: {
      borderTable
    },
  
    methods: {
      fangfa:function () {
        this.$refs.child.panduan();
      }
    }
  }
</script>

子组件代码

<template>
<div>我是子组件</div>

</template>

<script>
  import borderTable from '../tables/borderTable.vue'
    export default {
    components:{
      borderTable
    },
      methods: {
        panduan(){
         alert(“我是子组件我被调用了”)
        }
      }
    }
</script>
<style scoped>

</style>

猜你喜欢

转载自blog.csdn.net/Johnzhc/article/details/81203744