file-list.vue 1.0 KB

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