vue父组件促发子组件中的方法

实现在父组件中促发子组件里面的方法 子组件: <template> <div> 我是子组件 </div> </template> <script> export default { name: "child"...

实现在父组件中促发子组件里面的方法

子组件:

<template>
  <div>
    我是子组件
  </div>
</template>
 
<script>
  export default {
    name: "child",
    methods: {
     parentHandleclick(e) {
        console.log(e)
      }
  }
</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.parentHandleclick("父组件调用子组件方法");
      }
    }
  }
</script>
  • 发表于 2020-07-29 11:40
  • 阅读 ( 85 )
  • 分类:网络文章

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章
返回顶部
部分文章转自于网络,若有侵权请联系我们删除