Vue 使用 ElementUi el-upload 手动上传文件限制上传文件总大小
element
A Vue.js 2.0 UI Toolkit for Web
项目地址:https://gitcode.com/gh_mirrors/eleme/element
·
<el-upload
class="upload-demo"
action="#"
multiple
:auto-upload="false"
list-type="picture-card"
:file-list="modelForm.fileList"
:show-file-list="false"
:limit="3"
:on-change="handleChange"
>
<el-button size="small" type="primary">点击上传文件</el-button>
</el-upload>
// 文件状态改变时
handleChange(file) {
// 解构获取uid
let { uid } = file
// 计算总文件大小
const totalSize = this.modelForm.fileList.reduce(
(total, item) => total + item.size,
0
)
// (已上传文件大小 + 当前上传文件大小)大于100MB时
if (totalSize + size > 1024 * 1024 * 100) {
this.$message.warning('总文件大小不能超过100Mb')
const selectFileList = this.modelForm.fileList.filter(item => {
return item.uid != uid
})
this.modelForm.fileList = selectFileList
return
}
}
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45
7 个月前
a07f3a59
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update transition.md
* Update table.md
* Update table.md
* Update transition.md
* Update popover.md 7 个月前
更多推荐

所有评论(0)