为什么小程序多线程按照官方文档操作总是报错,怎么试也没有用?
{ "workers" : "workers"
|
workers/request/index.js workers/request/utils.js workers/response/index.js |
request/idnex.js
var utils = require( './utils' ) // 在 Worker 线程执行上下文会全局暴露一个 `worker` 对象,直接调用 worker.onMeesage/postMessage 即可 worker.onMessage( function (res) { console.log(res) }) |
app.js
var worker = wx.createWorker( 'workers/request/index.js' ) // 文件名指定 worker 的入口文件路径,绝对路径 //主线程向 Worker 发送消息 worker.postMessage({ msg: 'hello worker' }) |
6 回复
错误信息
Failed to load resource: the server responded with a status of 404 (Not Found) VM6838:1 appServiceSDKScriptError missing worker vendor code; at wx.createWorker Error: missing worker vendor code |
VM6838:1 thirdScriptError Cannot read property 'postMessage' of undefined;at App lifeCycleMethod onLaunch function TypeError: Cannot read property 'postMessage' of undefined |