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