vue 父组件中调用子组件函数的方法

2019-11-09,,,

在父组件中调用子组件的方法:

 1.给子组件定义一个ref属性。eg:ref="childItem"

 2.在子组件的methods中声明一个函数。eg: useInPar:function (str) {console.log(str)}

 2. 在父组件的中声明一个函数,并通过this.$refs.childItem.userInPar来使用子组件中声明的函数。

 父组件:

<template>
 <child-item ref='child' />
  <button @click='useChildFun'></button>
 </template>
 <script>
  ```
 methods() {
    useChildFun:function(){
      this.$refs.child.usedInPar('调用子组件中的方法');
   }
}
 </script>

子组件:

 ```
 methods () {
  usedInPar(str){
   console.log(str);
  }
 }

没有完整的代码,只有一个用法

总结

以上所述是小编给大家介绍的vue 父组件中调用子组件函数的方法,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对北冥有鱼网站的支持!

您可能感兴趣的文章:

  • vue父组件向子组件动态传值的两种方法
  • Vue父组件如何获取子组件中的变量
  • vue父组件触发事件改变子组件的值的方法实例详解
  • vue 父组件调用子组件方法及事件
  • Vue父组件调用子组件事件方法
  • vue 父组件通过$refs获取子组件的值和方法详解

《vue 父组件中调用子组件函数的方法.doc》

下载本文的Word格式文档,以方便收藏与打印。