index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script setup lang="ts">
  2. import {ref} from "vue";
  3. import Clients from "@/utils/upload";
  4. defineProps<{
  5. drag?: boolean;
  6. fileList?: [];
  7. }>()
  8. const handleGetOssToken = () => {
  9. console.log('获取token');
  10. }
  11. const handleBeforeUpload = async (file: File) => {
  12. }
  13. const handleUpload = (option: any) => {
  14. console.log('上传中', option);
  15. const {file} = option
  16. try {
  17. const client = new Clients()
  18. console.log(client)
  19. client.put(`${file.name}`, file).then((res: any) => {
  20. console.log('上传成功', res);
  21. option.onSuccess(res)
  22. }).catch((err: any) => {
  23. console.log('上传失败', err);
  24. option.onError(err)
  25. })
  26. } catch (e) {
  27. console.log(e)
  28. option.onError(e)
  29. }
  30. }
  31. </script>
  32. <template>
  33. <el-upload
  34. class="upload-demo"
  35. drag
  36. action="/"
  37. :http-request="handleUpload"
  38. :before-upload="handleBeforeUpload"
  39. :on-preview="(file) => { console.log('preview', file); }"
  40. :on-remove="(file, fileList) => { console.log('remove', file, fileList); }"
  41. :before-remove="(file, fileList) => { return $confirm(`确定移除 ${file.name}?`); }"
  42. :file-list="fileList"
  43. >
  44. <i class="el-icon-upload"></i>
  45. <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  46. </el-upload>
  47. </template>
  48. <style scoped lang="scss">
  49. </style>