Skip to content

Upload 上传

规则

js
{
    type: "upload",
    field: "pic",
    title: "轮播图",
    value: [
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg',
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg'
        ],
    props: {
        type:"select",
        uploadType:"image",
        action: "/upload.php",
        name:"pic",
        multiple: true,
        accept:"image\/*",
        limit: 2,
        onSuccess:function (res, file) {
            file.url = res.data.filePath;
        }
    },
}
{
    type: "upload",
    field: "pic",
    title: "轮播图",
    value: [
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg',
        'http://img1.touxiang.cn/uploads/20131030/30-075657_191.jpg'
        ],
    props: {
        type:"select",
        uploadType:"image",
        action: "/upload.php",
        name:"pic",
        multiple: true,
        accept:"image\/*",
        limit: 2,
        onSuccess:function (res, file) {
            file.url = res.data.filePath;
        }
    },
}

参考:Element_Upload

value :Array | String

注意

文件上传成功后需要通过 onSuccess 回调, 将接口返回内容中的 url 赋值给 file.url.否则表单获取不到组件的数据

Props

参数说明类型可选值默认值
action必选参数,上传的地址string
uploadType上传文件类型Stringimage(图片上传),file(文件上传)
headers设置上传的请求头部object
multiple是否支持多选文件boolean
data上传时附带的额外参数object
name上传的文件字段名stringfile
withCredentials支持发送 cookie 凭证信息booleanfalse
showFileList是否显示已上传文件列表booleantrue
drag是否启用拖拽上传booleanfalse
accept接受上传的文件类型(thumbnail-mode 模式下此参数无效)string
onPreview点击文件列表中已上传的文件时的钩子function(file)
onRemove文件列表移除文件时的钩子function(file, fileList)
onSuccess文件上传成功时的钩子 function (res, file) {file.url = res.data.filePath;} 通过给回调中的 file.url 赋值回显function(response, file, fileList)
onError文件上传失败时的钩子function(err, file, fileList)
onProgress文件上传时的钩子function(event, file, fileList)
onChange文件状态改变时的钩子,添加文件、上传成功和上传失败时都会被调用function(file, fileList)
beforeUpload上传文件之前的钩子,参数为上传的文件,若返回 false 或者返回 Promise 且被 reject,则停止上传。function(file)
beforeRemove删除文件之前的钩子,参数为上传的文件和文件列表,若返回 false 或者返回 Promise 且被 reject,则停止上传。function(file, fileList)
listType文件列表的类型stringtext/picture/picture-cardtext
autoUpload是否在选取文件后立即进行上传booleantrue
fileList上传的文件列表, 例如: [{name: 'food.jpg', url: 'https://xxx.cdn.com/xxx.jpg'}]array[]
httpRequest覆盖默认的上传行为,可以自定义上传的实现function
disabled是否禁用booleanfalse
limit最大允许上传个数number
onExceed文件超出个数限制时的钩子function(files, fileList)-
modalTitle图片预览弹出框标题文字String预览

Released under the MIT License.