微信小程序跨页面通信解决思路

} }

具体调用方法

App 是小程序的实例,在每个 Page 里都能通过执行 getApp 函数获取到它。我们可以把 Event 类的实例挂载在 App 中,方便每个 Page 去调用。

// 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){ ... }, ...})

在订单详情页支付成功的回调中,发布 “afterPaySuccess” 事件,同时带上订单 id 参数。

//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;">