fix(custom): 修复Upload组件上传成功但未取到值的问题
This commit is contained in:
@@ -6,7 +6,6 @@
|
||||
:custom-request="customRequest"
|
||||
:multiple="multiple"
|
||||
@before-upload="beforeUpload"
|
||||
@error="handleError"
|
||||
>
|
||||
点击上传
|
||||
</n-upload>
|
||||
@@ -41,10 +40,6 @@ const List = computed({
|
||||
},
|
||||
})
|
||||
|
||||
const handleError = () => {
|
||||
$message.error('上传失败')
|
||||
}
|
||||
|
||||
// 图片上传限制
|
||||
const beforeUpload = (data) => {
|
||||
if (!(data.file.file?.type === 'image/png' || data.file.file?.type === 'image/jpeg')) {
|
||||
@@ -54,12 +49,19 @@ const beforeUpload = (data) => {
|
||||
return true
|
||||
}
|
||||
|
||||
const customRequest = async ({ file, onFinish }) => {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file.file)
|
||||
const res = await api.uploadImg(formData)
|
||||
$message.success(res.msg)
|
||||
onFinish(res.data.data)
|
||||
const customRequest = async ({ file, onFinish, onError }) => {
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file.file)
|
||||
const res = await api.uploadImg(formData)
|
||||
$message.success(res.msg)
|
||||
file.url = res.data.data
|
||||
onFinish()
|
||||
} catch (e) {
|
||||
onError()
|
||||
$message.error('上传失败')
|
||||
throw e
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<CommonPage show-footer :title="$route.title">
|
||||
<!-- {{ model }} -->
|
||||
{{ model }}
|
||||
<n-spin size="large" :show="isShowSpin">
|
||||
<n-form ref="formRef" label-width="100" :model="model" :rules="rules" label-placement="left">
|
||||
<n-grid :cols="2" :x-gap="24">
|
||||
|
||||
Reference in New Issue
Block a user