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);