P粉7147807682023-09-03 10:01:15
One option is in <中使用workerCode>mounted()such as:
methods: { myFunction(){ console.log('It works!'); } }, mounted() { window["myWorker"] = new Worker("./myWorker.js"); window["myWorker"].onmessage = function(event) { if (event && event.data === 'run_my_function') { this.myFunction(); } } }
In myWorker.js
you can do this:
this.postMessage('run_my_function');