file-list.vue 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. <template>
  2. <el-upload
  3. v-model:file-list="fileList"
  4. class="upload-demo"
  5. action="https://run.mocky.io/v3/9d059bf9-4660-45f2-925d-ce80ad6c4d15"
  6. :on-change="handleChange"
  7. >
  8. <el-button type="primary">Click to upload</el-button>
  9. <template #tip>
  10. <div class="el-upload__tip">
  11. jpg/png files with a size less than 500kb
  12. </div>
  13. </template>
  14. </el-upload>
  15. </template>
  16. <script lang="ts" setup>
  17. import { ref } from 'vue'
  18. import type { UploadProps, UploadUserFile } from 'element-plus'
  19. const fileList = ref<UploadUserFile[]>([
  20. {
  21. name: 'food.jpeg',
  22. url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
  23. },
  24. {
  25. name: 'food2.jpeg',
  26. url: 'https://fuss10.elemecdn.com/3/63/4e7f3a15429bfda99bce42a18cdd1jpeg.jpeg?imageMogr2/thumbnail/360x360/format/webp/quality/100',
  27. },
  28. ])
  29. const handleChange: UploadProps['onChange'] = (uploadFile, uploadFiles) => {
  30. fileList.value = fileList.value.slice(-3)
  31. }
  32. </script>