在webworker中访问axios错误ReferenceError:axios__WEBPACK_IMPORTED_MODULE_0___未定义默认值

时间:2019-02-19 12:44:53

标签: reactjs axios web-worker

我使用create-react-app创建react app我想在app中使用web worker 对于使用axios但axios或我在工作文件中导入的任何库的文件上载,此错误引发“” ReferenceError:axios__WEBPACK_IMPORTED_MODULE_0___默认未定义“”

import axios from "axios";

export default function AppWorker(){

self.addEventListener("message", e => {

// eslint-disable-line no-restricted-globals

    if (!e) return;

    console.log(e.data.data)

    axios.get("www.example.com).then((e)=>{

      console.log(e)
    })

}

)}

// worker file




///////////////////////////////////
export default class WebWorker {

    constructor(worker) {

        const code = worker.toString();

        const blob = new Blob(['('+code+')()']);

        return new Worker(URL.createObjectURL(blob));
    }
}
// worker setup file


///////////////////////////////////////

    import React, { Component } from "react";

    import worker from './worker.js';

import WebWorker from './workerSetup';

export default class Home extends Component {

  constructor(props) {

    super(props);

  }

  componentDidMount = () => {

    this.worker = new WebWorker(worker);

  };

  addFile = e => {};

  handleChange = e => {

    console.log(e.target.files[0]);

    const fileObj = e.target.files[0];

    this.worker.postMessage("Hello World");

}

render() {

    return (

      <div>

        <input

          onChange={this.handleChange}

          placeholder="filer Uploader"

          type="file"

        />)
}

}
//home component

0 个答案:

没有答案