在不久前,咱们把vue-core-image-upload 发布了2.0 。此次咱们保持了完整的api迁移到了react上。支持了header 定义,支持了 file change 的自定义事件,更新了更加详细的文档。php
react-core-image-upload 项目地址css
Demohtml
使用 npmvue
npm install react-core-image-upload --save
使用 yarnreact
yarn add react-core-image-upload
import React from 'react'; import ReactCoreImageUpload from 'react-core-image-upload'; let App = React.createClass({ //... render() { return( <div> <ReactCoreImageUpload text="Upload Your Image" class={['pure-button', 'pure-button-primary', 'js-btn-crop']} inputOfFile="files" url="./api/upload.php" imageUploaded={this.handleRes}> </ReactCoreImageUpload> </div> ); }, handleRes(res) { this.setState({ // handle response }) } })
npm run start
http://localhost:9000/demo/index.htmlgit
Demo Onlinegithub
Props | Type | Example | Description |
---|---|---|---|
url | String | '/crop.php' | 服务端上传的地址 |
text | String | 'Upload Image' | 你须要显示按钮的文本 |
inputOfFile | String | 'file' | 上传服务端对应表单 name |
extensions | String | 'png,jpg,gif' | 限制的图片类型 |
crop | Boolean | true | 是否须要裁剪 |
cropRatio | String | '1:1' | 限制裁剪的形状 |
cropBtn | Object | {ok:'Save','cancel':'Give Up'} | 按钮文本 |
maxFileSize | Number | 10485760(10M) | 文件大小限制 |
maxWidth | Number | 150 | 限制裁剪图片的最大宽度 |
maxheight | Number | 150 | 限制裁剪图片的最大高度 |
inputAccept | string | 'image/*' / 'image/jpg,image/jpeg,image/png' | 赋予上传file的接受类型 |
isXhr | Boolean | true | 是否须要调用系统内本身的上传功能 |
headers | Object | {auth: xxxxx} | 设置xhr上传 的header |
imageUploaded
: 当图片上传成功后的响应处理npm
imageChanged
: 当选择图片后api
imageUploading
图片上传过程当中bash
errorHandle
图片上传中的异常处理
你使用裁剪的话,会向服务端发送上面的参数如上图。
若是你须要自定义裁剪弹窗的的样式,你能够本身写css进行覆盖