在父組件中調用子組件的方法:
 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 父組件中調用子組件函數的方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對錯新站長站網站的支持!
新聞熱點
疑難解答
圖片精選