具體調(diào)用方法
App 是小程序的實例,在每個 Page 里都能通過執(zhí)行 getApp
函數(shù)獲取到它。我們可以把 Event 類的實例掛載在 App 中,方便每個 Page 去調(diào)用。
// app.jsconst Event = require('./libs/event')App({ event: new Event(), ...})
訂單列表頁在 style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: #444444; border-radius: 4px; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; word-wrap: break-word; border: none; overflow-x: auto; background-color: #f6f6f6;">//order_list.jsvar app = getApp()Page({ onLoad: function(){ app.event.on('afterPaySuccess',this.afterPaySuccess.bind(this)) }, afterPaySuccess: function(orderId){ ... }, ...})
在訂單詳情頁支付成功的回調(diào)中,發(fā)布 “afterPaySuccess” 事件,同時帶上訂單 id 參數(shù)。
//order_detail.jsvar app = getApp()Page({ raisePayment: function(){ ... app.event.emit('afterPaySuccess', orderId) }, ...})
所有 Page 的 style="padding: 0.5em; font-family: Menlo, Monaco, Consolas, 'Courier New', monospace; color: #444444; border-radius: 4px; margin: 0px 0px 1.5em; font-size: 14px; line-height: 1.5em; word-break: break-all; word-wrap: break-word; border: none; overflow-x: auto; background-color: #f6f6f6;">