收藏
回答

navigateTo 两次跳转后,无法正常返回数据

框架类型 问题类型 API/组件名称 终端类型 微信版本 基础库版本
小程序 Bug wx.navigateBack() 微信iOS客户端 7.0.12 2.8.1

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


回答关注问题邀请回答
收藏

3 个回答

  • Aric
    Aric
    2020-10-10

    定义全局变量 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)
        })
      },
    })
    
    2020-10-10
    有用
    回复
  • 齐明
    齐明
    2020-05-30

    navigate经过2次跳转后,在back时没有触发最后一次的 eventChannel.emit

    写了个代码片段

    https://developers.weixin.qq.com/s/AeZFcImq7xhX

    2020-05-30
    有用
    回复
  • 疯狂的小辣椒
    疯狂的小辣椒
    2020-05-29

    请具体描述问题出现的流程,并提供能复现问题的简单代码片段https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

    2020-05-29
    有用
    回复 1
登录 后发表内容
问题标签