1. <template>
    2. <view>
    3. <uni-section title="只选择图片" type="line">
    4. <view class="example-body">
    5. <uni-file-picker :autoUpload="false" @select="handleSelect" @delete="handleDelete" limit="9"
    6. title="最多选择9张图片"></uni-file-picker>
    7. </view>
    8. </uni-section>
    9. </view>
    10. </template>
    11. <script>
    12. export default {
    13. data() {
    14. return {
    15. //上传的文件数据,实际的文件数据是tempFiles[i].file
    16. tempFiles: [],
    17. }
    18. },
    19. methods: {
    20. handleSelect(data) {
    21. //把上传的文件缓存一下
    22. this.tempFiles.push(...data.tempFiles)
    23. console.log('上传的图片信息', this.tempFiles);
    24. },
    25. handleDelete(data) {
    26. console.log(" data.tempFile", data.tempFile);
    27. //根据uuid找出要删除的文件index
    28. let index = this.tempFiles.findIndex(item => item.uuid === data.tempFile.uuid)
    29. if (index !== -1) {
    30. //删除对应的缓存文件
    31. this.tempFiles.splice(index, 1)
    32. console.log('删除后的图片信息', this.tempFiles);
    33. } else {
    34. console.log('没有查到对应的文件数据');
    35. }
    36. }
    37. }
    38. }
    39. </script>
    40. <style>
    41. </style>