如何解决如何从javascript手动抛出Filepond错误以保持原始验证的UI? image.vue
从 javascript 抛出 Filepond 错误以便在原始 FilePond UI 中完成所有操作是否可行?
我有 Filepond 实例,它可以验证图像类型和文件大小。 我也想验证文件长度,但据我所知,Filepond 不支持长度验证,所以我通过 js 手动完成了。我通过从 Filepond 加载 DatUrl 来获取图像宽度和高度。我想在比较图像宽度和图像高度时抛出错误。
image.vue
<template>
<file-pond
name="test"
ref="pond"
label-idle="Click here,or drop files here..."
accepted-file-types="image/jpg,image/jpeg,image/png"
label-file-type-not-allowed="change file types"
file-validate-type-label-expected-types="{allButLastType} or {lastType} is allowed"
label-max-file-size-exceeded="file size limit exceeded"
label-max-file-size="max file size 15MB"
max-file-size="15MB"
@addfile="addFile"
:disabled="isDisabled"
:allow-remove="false"
/>
</template>
<script>
async addFile(error,file: any) {
if (!error) {
try {
const base64DataUrl = file.getFileEncodeDataURL()
await Image.load(base64DataUrl).then((image) => {
if (image.width > image.height && image.height < 1000) {
# would lile to throw filepond error here
} else if (image.height > image.width && image.width < 1000) {
# same
}
});
} catch(error) {
console.log("error",error)
this.failedAddFile()
return
}
this.$emit("add-file",this.file)
}
}
</script>
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。