vue项目 多文件上传并显示在页面上

本文介绍了一个基于Vue的多文件上传组件实现,包括文件选择、显示文件名与大小、上传状态展示及删除功能。通过监听文件输入框的change事件,动态更新文件列表,并提供了删除按钮以移除待上传的文件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<template>
  <label for="file" class=" btn btn-default" style="border:1px solid red">多文件上传</label>
  <input type="file" style="display:none;" id="file" multiple @change="file()" name="multipartFiles">
  <table style="width:500px;margin:0 auto;" id="wenjian">
    <tr style="" id="col">
      <th class="name">文件名</th>
      <th class="size">大小</th>
      <th class="zhuangtai">状态</th>
      <th>操作</th>
    </tr>
    <tr :class="isactive?aaa:''" v-for="(dd,index) in wenjian" :key="index" id="tr">
      <td>{{dd.name}}</td>
      <td>{{(dd.size/1024).toFixed(1)}}kb</td>
      <td>等待上传</td>
      <td><button @click="del(index)">删除</button></td>
    </tr>
  </table>
</template>

date(){
  return{
    wenjian:[],
    isactive:true,
    aaa:'aaaclass'
  }
}

methods:{
 file(){
      var that = this;
      for(var ff=0;ff<$("#file")[0].files.length;ff++){
        that.wenjian.push($("#file")[0].files[ff])
      }
      that.isactive = false;
      //console.log($("#file")[0].files)
      //console.log(that.wenjian)      
    },
del(index){
      //console.log(111)
      var that = this;
      //console.log(that.wenjian)
      that.wenjian.splice(index,1)
    },
}


<style>.aaaclass{display:none;}</style>

效果图

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值