当前位置:网站首页>It is forbidden to trigger onchange in antd upload beforeupload
It is forbidden to trigger onchange in antd upload beforeupload
2022-07-06 16:14:00 【Dream height 1.8 meters】
Official website :https://ant.design/components/upload-cn/#components-upload-demo-upload-png-only
Add a little note :beforeUpload Property returns false or Promise.reject, It will only block uploading ( The upload request will not be triggered ), however onchange Function will still trigger , Want to stop onchange function , need beforeUpload return Upload.LIST_IGNORE
1 return false or Promise.reject
<html>
<head>
<script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/antd/4.20.6/antd.min.js" integrity="sha512-Pn2PLpM5OByFVBBfe517wK9LQCCbQsM4sVl7y3yHDCpHL/X/k6st3cre9SUiopZrbBiOQiSDgvKMOagM6MWCnA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/antd/4.20.6/antd.min.css" integrity="sha512-GKJ7hcKFof/Chhk79mhxA8egInBxwypeeD9sF/fAlTJ75n0YvjQ8mSofBD7KahRnMTzdtUFF5+YWjnXTew8Y0w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div id="root"></div>
</body>
<script type="text/babel"> const e = React.createElement; const custom = () => {
const [number, setNumber] = React.useState(0); const beforeUpload = file => {
const isPNG = file.type == 'image/png'; return isPNG; // return new Promise(()=>{
// const isPNG = file.type == 'image/png'; // if(isPNG) {
// resolve(); // } // else {
// reject(); // } // }) } const onChange = info => {
antd.message.info(' Trigger onchange') if (info.file.status == 'uploading') {
antd.message.info(' Uploading ') } if (info.file.status === 'done') {
antd.message.info(' Upload successful ') } else if (info.file.status === 'error') {
antd.message.info(' Upload failed ') } } return <antd.Upload name='file' action='https://www.mocky.io/v2/5cc8019d300000980a055e76' headers={
{
authorization: 'authorization-text', }} onChange={
info => onChange(info)} beforeUpload={
beforeUpload} > <antd.Button> Upload </antd.Button> </antd.Upload > } const domContainer = document.querySelector('#root'); ReactDOM.render(e(custom), domContainer); </script>
</html>
2 return Upload.LIST_IGNORE
<html>
<head>
<script src="https://unpkg.com/[email protected]/umd/react.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/umd/react-dom.development.js" crossorigin></script>
<script src="https://unpkg.com/[email protected]/babel.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/antd/4.20.6/antd.min.js" integrity="sha512-Pn2PLpM5OByFVBBfe517wK9LQCCbQsM4sVl7y3yHDCpHL/X/k6st3cre9SUiopZrbBiOQiSDgvKMOagM6MWCnA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/antd/4.20.6/antd.min.css" integrity="sha512-GKJ7hcKFof/Chhk79mhxA8egInBxwypeeD9sF/fAlTJ75n0YvjQ8mSofBD7KahRnMTzdtUFF5+YWjnXTew8Y0w==" crossorigin="anonymous" referrerpolicy="no-referrer" />
</head>
<body>
<div id="root"></div>
</body>
<script type="text/babel"> const e = React.createElement; const custom = () => {
const [number, setNumber] = React.useState(0); const beforeUpload = file => {
const isPNG = file.type == 'image/png'; return isPNG || antd.Upload.LIST_IGNORE; // return new Promise(()=>{
// const isPNG = file.type == 'image/png'; // if(isPNG) {
// resolve(); // } // else {
// return antd.Upload.LIST_IGNORE; // } // }) } const onChange = info => {
antd.message.info(' Trigger onchange') if (info.file.status == 'uploading') {
antd.message.info(' Uploading ') } if (info.file.status === 'done') {
antd.message.info(' Upload successful ') } else if (info.file.status === 'error') {
antd.message.info(' Upload failed ') } } return <antd.Upload name='file' action='https://www.mocky.io/v2/5cc8019d300000980a055e76' headers={
{
authorization: 'authorization-text', }} onChange={
info => onChange(info)} beforeUpload={
beforeUpload} > <antd.Button> Upload </antd.Button> </antd.Upload > } const domContainer = document.querySelector('#root'); ReactDOM.render(e(custom), domContainer); </script>
</html>
I tried , If you use promise, If you don't return resove()
or reject()
( Nothing returns ),onchange It doesn't trigger .
ps: Use in web pages react and antd The situation of , You can see this
https://blog.csdn.net/weixin_43915401/article/details/125046690
边栏推荐
- 渗透测试 2 --- XSS、CSRF、文件上传、文件包含、反序列化漏洞
- QT实现圆角窗口
- Flask框架配置loguru日志库
- Raspberry pie csi/usb camera uses mjpg to realize web camera monitoring
- Problem - 922D、Robot Vacuum Cleaner - Codeforces
- input 只能输入数字,限定输入
- 1605. Sum the feasible matrix for a given row and column
- [exercise-8] (UVA 246) 10-20-30== simulation
- 807. Maintain the urban skyline
- b站 实时弹幕和历史弹幕 Protobuf 格式解析
猜你喜欢
渗透测试 ( 3 ) --- Metasploit Framework ( MSF )
1855. Maximum distance of subscript alignment
(POJ - 3685) matrix (two sets and two parts)
807. Maintain the urban skyline
1903. Maximum odd number in string
Analysis of protobuf format of real-time barrage and historical barrage at station B
Luogu P1102 A-B number pair (dichotomy, map, double pointer)
[exercise-5] (UVA 839) not so mobile (balance)
7-1 understand everything (20 points)
Borg maze (bfs+ minimum spanning tree) (problem solving report)
随机推荐
605. Planting flowers
Basic Q & A of introductory C language
QT实现窗口置顶、置顶状态切换、多窗口置顶优先关系
1903. Maximum odd number in string
Classic application of stack -- bracket matching problem
图图的学习笔记-进程
(POJ - 2739) sum of constructive prime numbers (ruler or two points)
Flag framework configures loguru logstore
input 只能输入数字,限定输入
指定格式时间,月份天数前补零
QT按钮点击切换QLineEdit焦点(含代码)
Auto. Getting started with JS
Suffix expression (greed + thinking)
Write web games in C language
生成随机密码/验证码
Codeforces Round #797 (Div. 3)无F
渗透测试 ( 2 ) --- 渗透测试系统、靶机、GoogleHacking、kali工具
[exercise 4-1] cake distribution
useEffect,函数组件挂载和卸载时触发
MySQL grants the user the operation permission of the specified content