主进程接受不到 worker.postMessage消息?
发布于 5 年前 作者 xiaming 5736 次浏览 来自 问答

Page({

  data: {},
  
  onLoad: function () {
    this.worker = wx.createWorker('/worker/test.js');
    this.worker.onMessage(function (res) {
      console.log("主进程接受消息");
      console.log(res);
    });
    this.worker.postMessage({
      msg: "你好!!"
    });
  },
  onUnload: function(){
    this.worker.terminate();
  }
})

worker/test.js 代码:
worker.onMessage(function (message) {
  console.log("子进程worker输出");
  console.log(message);
  worker.postMessage({
    msg: "hello!!!"
  })
});
1 回复

你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html

回到顶部