W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
wepy.component基類提供三個(gè)方法$broadcast,$emit,$invoke,因此任一頁面或任一組件都可以調(diào)用上述三種方法實(shí)現(xiàn)通信與交互,如:
$this.$emit('some-event', 1, 2, 3, 4);
組件的事件監(jiān)聽需要寫在events屬性下,如:
import wepy form 'wepy';
export default class Com extends wepy.component {
components = {};
data = {};
methods = {};
events = {
'some-event': ($event, ...args) {
console.log(`${this.name} receive ${$event.name} from ${$event.source.name}`);
}
};
// Other properties
}
如果想在Page_Index中調(diào)用組件A的某個(gè)方法:
this.$invoke('ComA', 'someMethod', 'someArgs');
如果想在組件A中調(diào)用組件G的某個(gè)方法:
this.$invoke('./../ComB/ComG', 'someMethod', 'someArgs');
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: