UNPKG

3.44 kBMarkdownView Raw
1# bee-upload
2[![npm version](https://img.shields.io/npm/v/bee-upload.svg)](https://www.npmjs.com/package/bee-upload)
3[![Build Status](https://img.shields.io/travis/tinper-bee/bee-upload/master.svg)](https://travis-ci.org/tinper-bee/bee-upload)
4[![devDependency Status](https://img.shields.io/david/dev/tinper-bee/bee-upload.svg)](https://david-dm.org/tinper-bee/bee-upload#info=devDependencies)
5
6通过Upload可以将资源(web page,text,picture,video...)传到远程服务器
7
8## 使用
9
10### 使用单独的Upload包
11#### 组件引入
12先进行下载Upload包
13```
14npm install --save bee-upload
15```
16组件调用
17```js
18import { Upload } from 'bee-upload';
19
20const props = {
21 name: 'file',
22 action: '/upload.do',
23 headers: {
24 authorization: 'authorization-text',
25 },
26 onChange(info) {
27 if (info.file.status !== 'uploading') {
28 console.log(info.file, info.fileList);
29 }
30 if (info.file.status === 'done') {
31 console.log(`${info.file.name} file uploaded successfully`);
32 } else if (info.file.status === 'error') {
33 console.log(`${info.file.name} file upload failed.`);
34 }
35 },
36};
37
38class Demo1 extends Component {
39 render(){
40 return(
41 <Upload {...props}>
42 <Button type="primary" shape="border">
43 <Icon type="upload" /> Click to Upload
44 </Button>
45 </Upload>
46 )
47 }
48}
49
50React.render(<Demo1 />, document.getElementById('target'));
51```
52#### 样式引入
53- 可以使用link引入dist目录下upload.css
54```
55<link rel="stylesheet" href="./node_modules/build/bee-upload.css">
56```
57- 可以在js中import样式
58```js
59import "./node_modules/src/Upload.scss"
60//或是
61import "./node_modules/build/bee-upload.css"
62```
63
64
65
66## API
67
68|参数|说明|类型|默认值|
69|---|----|---|------|
70|name|文件名|string|file|
71|defaultFileList|默认已上传的文件列表|array|-|
72|fileList|已上传的文件列表,多用于onChange事件里|array|-|
73|action|上传的服务器地址|array|-|
74|data|上传参数或者函数 |Object or function|-|
75|headers|设置请求的头部信息 兼容ie10以上|object|-|
76|showUploadList|是否显示上传列表|bool|true|
77|multiple|是否支持多文件上传 兼容ie10以上|bool|false|
78|accept|设置文件接收类型|string|-|
79|beforeUpload|在上传之前执行的函数,当Promise返回false或者被拒绝,函数被中指。不兼容老ie|func|-|
80|customRequest|覆盖默认的XHR,可定制自己的XMLHttpRequest|func|-|
81|onChange|当上传状态改变之后执行的回调函数|func|-|
82|listType|内置的样式,支持text和picture|string|'text'|
83|onRemove|当删除按钮点击后触发的回调函数|func|-|
84|supportServerRender|当服务器正在渲染时,是否需要打开|bool|false|
85
86### onChange
87
88当文件正在上传,上传成功和上传失败触发的回调函数。
89当上传状态发生变化,返回下列参数。
90
91```
92{
93 file: {
94 uid: 'uid', // 唯一性id
95 name: 'xx.png' // 文件名
96 status: 'done', // 参数:uploading, done, error, removed
97 response: '{"status": "success"}', // 服务器返回的参数
98 },
99 fileList: [ /* ... */ ], //当前文件列表
100 event: { /* ... */ }, //服务器响应:包括上传进度 不兼容老的浏览器
101}
102```
103
104#### 开发调试
105
106```sh
107$ git clone https://github.com/tinper-bee/bee-upload
108$ cd bee-upload
109$ npm install
110$ npm run dev
111```