vue獲取子組件數據的三個方法


1.this.$emit ,子傳父

2.this.$children屬性

this.$children返回的是數組

例子:

//獲取子組件數據
       console.log(this.$children[0].cdata);
 //調用子組件方法
    this.$children[0].cmethod()

 

3.通過this.$refs獲取組件

 //獲取子組件數據
       console.log(this.$refs.test.cdata);
//調用子組件方法
    this.$refs.test.cmethod()

 

4.this.$parent獲取父組件數據

this.$parent返回的是對象,this.$children返回的數組

例子:

 console.log(this.$parent.pdata);

 


免責聲明!

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



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