A页面通过wx.navigateTo方法跳转的B页面

A页面js代码:

wx.navigateTo({
url: 'B页面路径',
success: function (res) {
// 通过eventChannel向被打开页面传送数据
res.eventChannel.emit('acceptDataFromOpenerPage', { username: '小诸葛'})
}
})

B页面js代码(在onLoad方法内接收A页面传递的参数):

onLoad: function(options) {

let that = this;
const eventChannel = that.getOpenerEventChannel()
eventChannel.on('acceptDataFromOpenerPage', function(data) {
console.log("username:" + data.username);
})

}