Material-UI LinearProgress bar not working

前端 未结 2 825
别跟我提以往
别跟我提以往 2021-01-20 06:39

I have a simple file upload utility, for which I am using react-dropzone, and in conjunction to that I wanted to use material-ui LinearProgress bar to show the progress.

2条回答
  •  隐瞒了意图╮
    2021-01-20 07:12

    Complete example:

    import React, { Component } from "react";
    import ReactDOM from "react-dom";
    import Dropzone from "react-dropzone";
    import request from "superagent";
    import { Line } from 'rc-progress';
    
    class App extends Component {
      state = {
          completed: 0
      }
    
      onDrop = files => {
        this.setState({ completed: 0 });
        var data = new FormData();
        files.forEach(file => {
          data.append("files[]", file, file.name);
        });
    
        var req = request.post("http://localhost:3001");
        req.on('progress', event => {
          var percent = Math.floor(event.percent);
          if (percent >= 100) {
            this.setState({ completed: 100 });
          } else {
            this.setState({ completed: percent });
          }
        });
    
        const that = this;
        req.send(data);
        req.end((err, res) => {
          console.log("Successfully uploaded");
        });
      };
    
      render() {
        const divStyle = {
          border: '1px solid black'
        };
        return (
          
    Try dropping some files here, or click to select files to upload. {this.state.completed}
    ); } } ReactDOM.render(, document.getElementById("root"));

提交回复
热议问题