300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > antd 上传进度_antd upload 如何控制进度条 官方的例子里都没有设置onprogress

antd 上传进度_antd upload 如何控制进度条 官方的例子里都没有设置onprogress

时间:2024-01-03 14:11:09

相关推荐

antd 上传进度_antd upload 如何控制进度条 官方的例子里都没有设置onprogress

楼上正解,这是我从官方实例复制的代码,

import { Upload, Icon, message } from 'antd';

function getBase64(img, callback) {

const reader = new FileReader();

reader.addEventListener('load', () => callback(reader.result));

reader.readAsDataURL(img);

}

function beforeUpload(file) {

const isJPG = file.type === 'image/jpeg';

if (!isJPG) {

message.error('You can only upload JPG file!');

}

const isLt2M = file.size / 1024 / 1024 < 2;

if (!isLt2M) {

message.error('Image must smaller than 2MB!');

}

return isJPG && isLt2M;

}

class Avatar extends ponent {

state = {};

handleChange = (info) => {

if (info.file.status === 'done') {

// Get this url from response in real world.

getBase64(info.file.originFileObj, imageUrl => this.setState({ imageUrl }));

}

}

render() {

const imageUrl = this.state.imageUrl;

return (

className="avatar-uploader"

name="avatar"

showUploadList={false}

action="///posts/"

beforeUpload={beforeUpload}

onChange={this.handleChange}

>

{

imageUrl ?

:

}

);

}

}

ReactDOM.render(, mountNode);

antd 上传进度_antd upload 如何控制进度条 官方的例子里都没有设置onprogress 可是有的例子有进度条 有的例子却没有...

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。