A页面navigateTo B页面,然后B页面 navigateTo C页面 代码如下
A页面
wx.navigateTo({
url: '../../my/customer/customerList/customerList?from=customerStatistics',
events:{
sendDataFromCustomerList:data=>{
console.log(data);
}
}
});
B页面
wx.navigateTo({
url:'../customerSearch/customerSearch?from='+this.data.from,
events:{
sendDataFromCustomerSearch: data => {
console.log("=======>",data);
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('sendDataFromCustomerList',data);
wx.navigateBack();
}
}
})
C页面
const eventChannel = this.getOpenerEventChannel()
eventChannel.emit('sendDataFromCustomerSearch', {customer:this.data.customerList[event.currentTarget.id]});
wx.navigateBack();
期望C页面的数据返回给B页面,B页面再返回给A页面
问题是现在B页面接收到了数据,但是A页面并没有监听到B页面发送的事件,也就没有接收到数据
当我把B页面发送数据的代码EventChannel.emit 添加timeOut 100毫秒后,就正常了
微信开发工具版本号 稳定版 Stable Build (1.03.2005140)
调试基础库 2.8.1
真机测试
iPhone8 iOS 13.4.1
定义全局变量 eventChannel 并在页面 onLoad 中初始化,后续使用全局变量 eventChannel 触发事件就没问题了
//test.js let eventChannel Page({ onLoad: function(option) { console.log(option.query) eventChannel = this.getOpenerEventChannel() eventChannel.emit('acceptDataFromOpenedPage', { data: 'test' }) eventChannel.emit('someEvent', { data: 'test' }) // 监听acceptDataFromOpenerPage事件,获取上一页面通过eventChannel传送到当前页面的数据 eventChannel.on('acceptDataFromOpenerPage', function(data) { console.log(data) }) }, })
navigate经过2次跳转后,在back时没有触发最后一次的 eventChannel.emit
写了个代码片段
https://developers.weixin.qq.com/s/AeZFcImq7xhX
请具体描述问题出现的流程,并提供能复现问题的简单代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html
写了个代码片段
https://developers.weixin.qq.com/s/AeZFcImq7xhX