簡體   English   中英

在反應中使用網絡工作者

[英]using web-worker in react

// 這是我的網絡工作者代碼

 import * as d3 from 'd3'; // import d3 from 'https://d3js.org/d3-collection.v1.min.js'; // importScripts('d3'); //fibo.worker.js // eslint-disable-next-line import/no-anonymous-default-export export default () => { // eslint-disable-next-line no-restricted-globals self.onmessage = (message) => { const { nodes, links, width, height } = message.data; const simulation = d3.forceSimulation(nodes).force( 'link', d3.forceLink(links) // This force provides links between nodes.id((d) => d.id) // This sets the node id accessor to the specified function. If not specified, will default to the index of a node. .distance(10) ).force('charge', d3.forceManyBody().strength(-500)) // This adds repulsion (if it's negative) between nodes. .force('center', d3.forceCenter(width / 3, height / 3)).force( 'collision', d3.forceCollide().radius((d) => d.radius) ); postMessage(simulation); }; };
我收到一個錯誤

未捕獲的 ReferenceError:d3__WEBPACK_IMPORTED_MODULE_0__ 未在 self.onmessage 中定義

原因:import * as d3 from 'd3'; 刪除它並使用@ts-ignore

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM