<script>
    export default{
        data(){
            return {
                pic:''
            }
        },
        methods:{
            success(res,file,fileList){
                this.pic=res.id
            },
            process(event, file, fileList){
                console.log(event, file, fileList)
            },
            error(err, response, file){
                console.log(err, response, file)
            },
            change(files){
                this.$message.info(`上传文件数为${files.length}`);
            }
        }
    }
</script>
<style lang='less'>
    .demo-drag{
        width:380px;
        color:#99a9bf;
        .utear-icon-cloud{
            line-height:110px;
            font-size:80px;
        }
        p{
            font-size:13px;
            em{
                color:#20a0ff;
                font-style:normal;
            }
        }
    }
</style>

# Upload上传

文件选择上传和拖拽上传控件。
## 何时使用

* 上传是将信息（网页、文字、图片、视频等）通过网页或者上传工具发布到远程服务器上的过程。
* 当需要上传一个或一些文件时。
* 当需要展现上传的进度时。
* 当需要使用拖拽交互时。

### 单文件上传

::: demo 点击上传多个文件
```html
<template>
    <ut-upload  action="//jsonplaceholder.typicode.com/posts/" name='file' multiple style='width:400px' upload-list>
        <ut-button type='primary'>上传</ut-button>
    </ut-upload>
</template>
```
:::

### 上传文件夹

::: demo 点击上传多个文件
```html
<template>
    <ut-upload  action="//jsonplaceholder.typicode.com/posts/" directory name='file' multiple style='width:400px' upload-list>
        <ut-button type='primary'>上传</ut-button>
    </ut-upload>
</template>
```
:::

### 组件事件

::: demo 
```html
<template>
    <ut-upload  action="//jsonplaceholder.typicode.com/posts/" @change='change' name='file' multiple style='width:400px' upload-list>
        <ut-button type='primary'>上传</ut-button>
    </ut-upload>
</template>
<script>
    export default{
        methods:{
            change(files){
                this.$message.info(`上传文件数为${files.length}`);
            }
        }
    }
</script>
```
:::

### 自定义样式

::: demo 自定义样式
```html
<template>
    <ut-upload  action="//jsonplaceholder.typicode.com/posts/" name='test' @success='success'  @process='process' @error='error' style='width:400px'>
        <ut-input v-model='pic'>
            <template slot='addonAfter'>
                <ut-button type='primary'>上传</ut-button>
            </template>
        </ut-input>
    </ut-upload>
</template>
<script>
    export default{
        data(){
            return {
                pic:''
            }
        },
        methods:{
            success(res,file,fileList){
                this.pic = res.id
            },
            process(event, file, fileList){
                console.log(event, file, fileList)
            },
            error(err, response, file){
                console.log(err, response, file)
            }
        }
    }
</script>
```
:::

### 拖拽上传

::: demo  可将文件拖入指定区域进行上传。将 type 属性指定为 'drag' 可以将上传控件变为支持拖拽的形式，并且你可以通过 multiple 属性来控制是否支持多选
```less
<template>
    <ut-upload  action="//jsonplaceholder.typicode.com/posts/" 
            name='test'
            multiple type='drag' 
            class='demo-drag' 
            upload-list>
        <i class='utear-icon-cloud utear-icon'></i>
        <p>将文件拖到此处，或<em>点击上传</em></p>
    </ut-upload>
</template>
<style lang='less'>
    .demo-drag{
        width:380px;
        color:#99a9bf;
        .utear-icon-cloud{
            line-height:110px;
            font-size:80px;
        }
        p{
            font-size:13px;
            em{
                color:#20a0ff;
                font-style:normal;
            }
        }
    }
</style>
```
:::

## API

|参数         |说明           | 类型|默认值|
|---------- |-------- |---------- |-------------  |
| action	 | 必选参数, 上传的地址  | string  |  -          |
| headers    |可选参数, 设置上传的请求头部  | object  | -      |
|multiple|可选参数, 是否支持多选文件| boolean  | false        |
| data |可选参数, 上传时附带的额外参数   | object  | -          |
| name |可选参数, 上传的文件字段名 | string  | file        |
| directory |可选参数,可上传文件夹 | boolean  | false        |
|upload-list|是否显示已上传文件列表| boolean |false|
| type |上传控件类型(select,drag)|string| select |
| accept|可选参数, 接受上传的[文件类型](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input#attr-accept)|string|-|
|success|可选参数, 文件上传成功时的钩子|function(response, file, fileList)|-|
|error|	可选参数, 文件上传失败时的钩子	|function(err, response, file)|-|
|progress	|可选参数, 文件上传时的钩子	|function(event, file, fileList)|-|	
|change	|可选参数, 组件更改时触发|function(files)|-|	