在 Naive UI 中,Upload 组件确实没有提供 on-success 方法。但是,你可以使用 on-update:fileon-update:files 方法来监听文件上传的状态,并获取返回的结果。

以下是一个示例代码:

<template>
  <na-upload
    action="/upload"
    :on-update:file="handleFileUpdate"
  >
    <na-button>点击上传</na-button>
  </na-upload>
</template>

<script>
export default {
  methods: {
    handleFileUpdate(file) {
      if (file.status === 'success') {
        // 文件上传成功,可以获取返回的结果
        console.log(file.response)
      }
    }
  }
}
</script>

handleFileUpdate 方法中,你可以根据 file.status 的值判断文件上传的状态。当 file.status 等于 'success' 时,表示文件上传成功,你可以通过 file.response 获取返回的结果。

需要注意的是,file 对象的具体属性可能会根据后端服务器的返回结果而有所不同,具体的属性和获取方法可以根据你的实际情况进行调整。

Naive UI Upload 组件获取上传结果:on-update:file 方法详解

原文地址: https://www.cveoy.top/t/topic/o96A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录