vue父組件點擊事件調用子組件方法


第一步:

在子組件注冊一個方法

比如

showSure(){
            this.show=true
            console.log('成功調用子組件方法')
 },
 
然后再父組件中
 <button @click="getChild">點擊調用子組件</button>3

 <!-- 子組件注冊個ref -->
  <toast ref="child1"></toast>
 

<script>
import toast from './toast'//引入子組件
export default {
    components:{toast},//注冊組件
    name:'login',
    methods:{
        getChild(){
            this.$refs.child1.showSure() //child1是寫在子組件上的屬性 showSure()是子組件的方法名

            
        }
    }
}
</script>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM