You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
781 B
30 lines
781 B
//work-loader使用示例
|
|
//vue2 配置vue.config.js中增加
|
|
/**
|
|
* config.module.rule('worker')
|
|
* .test(/\.worker\.js$/)
|
|
* .use('worker-loader')
|
|
* .loader('worker-loader')
|
|
* .options({ inline: 'fallback' }).end()
|
|
*/
|
|
//主程序使用
|
|
/**
|
|
* import Worker from './sliao.worker?v=10' 这里注意修改work线程函数时需要修改版本号才能生效
|
|
* const worker = new Worker();
|
|
* worker.onmessage = ({data}) => {
|
|
* console.log('获取到处理的数据', data);
|
|
* };
|
|
* function sendMessage() {
|
|
* worker.postMessage(['第一条', '第二条', '第三条','第三条']);
|
|
* }
|
|
* sendMessage()
|
|
*/
|
|
|
|
//*.work.js
|
|
onmessage = (e)=>{
|
|
console.log(1234)
|
|
const {data}=e
|
|
console.log(data)
|
|
postMessage(data)
|
|
}
|