upload.vue 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <template>
  2. <el-upload
  3. class="upload-demo"
  4. action="https://jsonplaceholder.typicode.com/posts/"
  5. :on-preview="handlePreview"
  6. :on-remove="handleRemove"
  7. multiple
  8. :limit="3"
  9. :file-list="fileList"
  10. >
  11. <el-button type="primary">Click to upload</el-button>
  12. <template #tip>
  13. <div class="el-upload__tip">
  14. jpg/png files with a size less than 500kb
  15. </div>
  16. </template>
  17. </el-upload>
  18. </template>
  19. <script lang="ts" setup>
  20. import { ref } from 'vue'
  21. import type { UploadUserFile, UploadFile } from 'element-plus'
  22. const fileList = ref<UploadUserFile[]>([
  23. {
  24. name: 'food.jpeg',
  25. url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
  26. },
  27. {
  28. name: 'food2.jpeg',
  29. url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
  30. },
  31. ])
  32. const handleRemove = (file: UploadFile, fileList: UploadFile[]) => {
  33. console.log(file, fileList)
  34. }
  35. const handlePreview = (file: UploadFile) => {
  36. console.log(file)
  37. }
  38. </script>