| 注册
请输入搜索内容

热门搜索

Java Linux MySQL PHP JavaScript Hibernate jQuery Nginx
jopen
9年前发布

在React.js中实现拖放上传:react-dropzone

简单的HTML5拖放上传文件在React.js中。

Screenshot of Dropzone

示例: http://paramaggarwal.github.io/react-dropzone/

安装

The easiest way to use react-dropzone is to install it from npm and include it in your React build process (using Webpack, Browserify, etc).

npm install --save react-dropzone

用法

Simplyrequire('react-dropzone')and specify anonDropmethod that accepts an array of dropped files. You can customize the content of the Dropzone by specifying children to the component.

You can specify astyleobject to apply some basic styles to theDropzonecomponent, or alternatively use theclassNameproperty to style the component with custom CSS.

If nostyleorclassNameproperties are defined, the style object will default to thewidthandheightproperties (or100pxif they aren't defined) along with aborderStyleof "solid" or "dashed" depending on if drag actions are taking place.

You can alternatively specify asizeproperty which is an integer that sets bothstyle.widthandstyle.heightto the same value.

By default the drop zone can be clicked to bring up the browser file picker. To disable this thesupportClickproperty should be set tofalse.

Also multiple files can be uploaded to the drop zone, but this can be disabled by setting themultipleproperty tofalse. The allowed file types can be controlled by theacceptproperty, using the same syntax as the HTML accept Attribute.

示例

/** @jsx React.DOM */  var React = require('react');  var Dropzone = require('react-dropzone');    var DropzoneDemo = React.createClass({      onDrop: function (files) {        console.log('Received files: ', files);      },        render: function () {        return (            <div>              <Dropzone onDrop={this.onDrop} width={150} height={100}>                <div>Try dropping some files here, or click to select files to upload.</div>              </Dropzone>            </div>        );      }  });    React.render(<DropzoneDemo />, document.body);

项目主页:http://www.open-open.com/lib/view/home/1438440649347

 本文由用户 jopen 自行上传分享,仅供网友学习交流。所有权归原作者,若您的权利被侵害,请联系管理员。
 转载本站原创文章,请注明出处,并保留原始链接、图片水印。
 本站是一个以用户分享为主的开源技术平台,欢迎各类分享!
 本文地址:https://www.open-open.com/lib/view/open1438440649347.html
文件上传 react-dropzone