zoukankan      html  css  js  c++  java
  • react里面的upload上传及上传格式操作

    import React from 'react'
    import {
      Form,
      Button,
      Upload,
      Icon,
      message,
    } from 'antd'

    export default @Form.create({
      onValuesChange(_, values) {
        console.log(values, 1)
      }
    })
    class Home extends React.Component {
      handleSubmit = e => {
        e.preventDefault()
        this.props.form.validateFields((err, values) => {
          if (!err) {
            console.log(values, 3)
          }
        })
      }

      onBeforeUpload = ({ type }) => {
        if (type !== 'image/png') {
          message.warning('格式不对')
          return false
        }
      }

      normFile = e => {
        if (e.file.type !== 'image/png') return false
        if (Array.isArray(e)) return e
        return e && e.fileList
      }

      render() {
        const { getFieldDecorator } = this.props.form
        const formItemLayout = {
          labelCol: { span: 6 },
          wrapperCol: { span: 14 },
        }
        return (
          <Form {...formItemLayout} onSubmit={this.handleSubmit}>
            <Form.Item label="Upload">
              {getFieldDecorator('upload', {
                valuePropName: 'fileList',
                getValueFromEvent: this.normFile,
              })(
                <Upload
                  name="logo" 
                  action="https://www.mocky.io/v2/5cc8019d300000980a055e76" 
                  listType="picture"
                  beforeUpload={this.onBeforeUpload}
                >
                  <Button>
                    <Icon type="upload" /> Click to upload
                  </Button>
                </Upload>,
              )}
            </Form.Item>

            <Form.Item wrapperCol={{ span: 12, offset: 6 }}>
              <Button type="primary" htmlType="submit">
                Submit
              </Button>
            </Form.Item>
          </Form>
        )
      }
    }
  • 相关阅读:
    微服务-分布式事务解决方案
    Python cannot import name 'Line' from 'pyecharts'
    powershell 基础
    Linux SSH config
    神奇的Python代码
    GitHub 中 readme 如何添加图片
    Linux 笔记(自用)
    Anaconda 安装 TensorFlow ImportError:DLL加载失败,错误代码为-1073741795
    Ubuntu 分辨率更改 xrandr Failed to get size of gamma for output default
    Git入门教程 Git教程入门
  • 原文地址:https://www.cnblogs.com/LC123456/p/12912852.html
Copyright © 2011-2022 走看看