vue-simple-uploader 上传组件如何过滤掉文件夹?

用到了第三方上传组件 vue-simple-uploader,但是不需要支持文件夹上传,所以需要过滤掉文件夹,但是拖拽上传时是可以选择文件夹的,该如何过滤掉文件夹呢?

阅读 860
2 个回答
<template>
  <div>
    <uploader :options="options" class="uploader-example">
      <uploader-drop @drop="handleDrop">
        <p>Drop files here to upload or</p>
        <uploader-btn>select files</uploader-btn>
      </uploader-drop>
      <uploader-list></uploader-list>
    </uploader>
  </div>
</template>

<script>
export default {
  data() {
    return {
      options: {
        target: '//localhost:3000/upload',
        testChunks: false,
      },
    };
  },
  methods: {
    handleDrop(event) {
      const items = event.dataTransfer.items;
      const files = [];

      for (let i = 0; i < items.length; i++) {
        const item = items[i].webkitGetAsEntry();
        if (item && item.isFile) {
          files.push(items[i].getAsFile());
        }
      }

      // Process the files array as needed
      console.log('Filtered files:', files);
    },
  },
};
</script>

<style>
.uploader-example {
  width: 880px;
  padding: 15px;
  margin: 40px auto 0;
  font-size: 12px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.4);
}
.uploader-example .uploader-btn {
  margin-right: 4px;
}
.uploader-example .uploader-list {
  max-height: 440px;
  overflow: auto;
  overflow-x: hidden;
  overflow-y: auto;
}
</style>
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
宣传栏