Skip to content

Commit 07f6051

Browse files
committed
fix(imgUpload): 修复远程方法为promise时的错误
1 parent ac183a8 commit 07f6051

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/components/base/upload-imgs/index.vue

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -526,20 +526,10 @@ export default {
526526
// 如果是用户自定义方法
527527
// 出于简化 api 的考虑, 只允许单个文件上传
528528
if (this.remoteFuc) {
529-
// promise 模式
530-
if (this.remoteFuc.then) {
531-
const remoteData = await this.remoteFuc(item.file)
532-
reduceResult(item, remoteData)
533-
if (!remoteData) {
534-
return false
535-
}
536-
return item
537-
}
538-
539529
// 回调函数模式
540530
if (typeof this.remoteFuc === 'function') {
541531
return new Promise((resolve) => {
542-
this.remoteFuc(item.file, (data) => {
532+
const a = this.remoteFuc(item.file, (data) => {
543533
reduceResult(item, data)
544534
if (!data) {
545535
this.$message.error('执行自定义上传出错')
@@ -548,6 +538,16 @@ export default {
548538
resolve(item)
549539
}
550540
})
541+
// promise 模式
542+
if (a != null && typeof a.then === 'function') {
543+
a.then((remoteData) => {
544+
reduceResult(item, remoteData)
545+
if (!remoteData) {
546+
resolve(false)
547+
}
548+
resolve(item)
549+
})
550+
}
551551
})
552552
}
553553

0 commit comments

Comments
 (0)