松鼠的博客

导航

统计

vue中文件上传方法

1.单文件上传

<template>
  <div>
    <label for="fileInput">
      <i aria-hidden="true" class="cursor">上传文件</i>
    </label>
    <input
      v-show="false"
      type="file"
      id="fileInput"
      @change="handleFileChange"
      name="file"
      ref="file"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  methods: {
    handleFileChange(e) {
      let _this = this;
      let file = e.target.files;
      console.log(file,"单文件流文件流");
    }
  }
};
</script>

<style lang="scss" scoped>
.cursor {
  cursor: pointer;
  color: #409eff;
  font-size: 16px;
}
</style>

2.多文件上传
在input上加属性 multiple="multiple"即可实现多文件上传,也可以设置文件上传类型是在input上加属性 accept=".xls, .xlsx"

<template>
  <div>
    <label for="fileInput">
      <i aria-hidden="true" class="cursor">上传文件</i>
    </label>
    <input
      v-show="false"
      type="file"
      id="fileInput"
      @change="handleFileChange"
      accept=".xls, .xlsx"
      name="file"
      ref="file"
      multiple="multiple"
    />
  </div>
</template>

<script>
export default {
  data() {
    return {};
  },
  methods: {
    handleFileChange(e) {
      let _this = this;
      let file = e.target.files;
     console.log(file,"多文件文件流文件流");
    }
  }
};
</script>

<style lang="scss" scoped>
.cursor {
  cursor: pointer;
  color: #409eff;
  font-size: 16px;
}
</style>

vant中方法

 

 

参考文章:http://blog.ncmem.com/wordpress/2023/11/15/vue%e4%b8%ad%e6%96%87%e4%bb%b6%e4%b8%8a%e4%bc%a0%e6%96%b9%e6%b3%95/

欢迎入群一起讨论

 

 

posted on   Xproer-松鼠  阅读(216)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2019-11-15 文件分片上传
2019-11-15 大文件分片上传
2019-11-15 pdf缩略图生成上传解决方案
2019-11-15 psd缩略图生成上传解决方案
2019-11-15 pdf缩略图上传组件
2019-11-15 pdf缩略图上传控件
2019-11-15 psd缩略图上传组件
点击右上角即可分享
微信分享提示