参数 | 说明 | 类型 | 可选 | 默认 | 必填 |
---|---|---|---|---|---|
action | 自动上传必选参数,上传的地址 | String | - | - | 否 |
autoUpload | 是否自动上传 | boolean | true/false | false | 否 |
data | 上传时附带的额外参数 | object | - | - | 否 |
listType | 上传样式类型 | String | head,text/picture/picture-card | - | 是 |
showFileList | 是否显示上传列表(上传头像,必须false) | boolean | true/false | false | 否 |
drag | 是否使用拖拽 (text/pictures 模式使用) | String | - | - | 否 |
limit | 最大允许上传个数 | number | - | - | 否 |
isIcon | 是否开启icon模式 (仅限picture) | boolean | true/false | false | 否 |
tip | 元素最底部添加的提示语 | String | - | - | 否 |
fileList | 回显数据列表 | array | - | - | 否 |
fileType | 设置上传的文件类型 | array | - | - | 是 |
fileSize | 设置上传的文件大小(KB形式结算) | number | - | - | 是 |
styleOptions | 上传框样式控制 (只限上传头像使用,其他的请用样式控制) | object | - | - | 否 |
kb算法:1KB=1024B 1MB(M)=1024KB 1GB=1024MB;
event事件
参数 | 说明 | 回调参数 |
---|---|---|
success | 文件上传成功时的钩子(手动上传,触发change事件就会回调) | value |
error | 文件上传失败时的钩子 | value |
remove | 文件列表移除文件时的钩子 | value |
<template>
<div>
<wb-upload
:action="uploadInfo.action"
:autoUpload="uploadInfo.autoUpload"
:listType="uploadInfo.listType"
:showFileList="uploadInfo.showFileList"
:styleOptions="uploadInfo.styleOptions"
:fileType="uploadInfo.fileType"
:fileSize="uploadInfo.fileSize"
:tip="uploadInfo.tip"
:fileList="uploadInfo.fileList"
:drag="uploadInfo.drag"
:limit="uploadInfo.limit"
:isIcon="uploadInfo.isIcon"
@success="uploadSuccessFn"
@error="uploadErrorFn"
@remove="uploadRemoveFn"
>
</wb-upload>
</div>
</template>
<script>
export default {
name: 'wb-ceshiupload',
data () {
return {
uploadInfo: {
action: 'https://jsonplaceholder.typicode.com/posts/', // 上传地址 (自动上传时,必填)
autoUpload: false, // 是否自动上传 (默认false)
listType: 'picture', // 文件列表的类型
showFileList: true, // 是否显示上传列表(上传头像,必须false)
tip: '只能上传jpg/png文件,且不超过500kb', // 提示语
drag: false, // 是否使用拖拽 (text/pictures 模式使用)
fileList: [], // 回显数据列表
limit: 100, // 最大允许上传个数
isIcon: true, // 是否开启icon模式 (仅限picture)
// 上传框样式控制 (只限上传头像使用,其他的请用样式控制)
styleOptions: {
width: '100px',
height: '100px',
lineHeight: '100px',
},
fileType: ['jpg','png'], // 设置上传的文件类型
fileSize: 500 // 设置上传的文件大小(以KB结算)
}
}
},
methods: {
// 上传成功
uploadSuccessFn (res) {
console.log(res)
},
// 上传失败
uploadErrorFn (err) {
console.log(err)
},
// 删除回调
uploadRemoveFn (res) {
console.log(res)
},
}
}
</script>
<style scoped>
</style>