vue批量上传图片并编辑图片名称

在写一个批量上传图片的功能

直接看代码吧,

 <el-upload class="avatar-uploader"  multiple :action="上传接口" :headers="请求头,可根据自己情况配置" :show-file-list="false" :on-success="handleAvatarSuccess">
         <el-button style="margin:20px 0 20px -70px; " slot="trigger" size="small" type="primary">点击上传图片</el-button>
 </el-upload>
 <el-table v-loading="loading" class='courselist' :data="uploadList">
        <el-table-column label="文件名称" align='center'>
				<template slot-scope="scope">
					<p>{{scope.row.name}}</p>
				</template>
		</el-table-column>
        <el-table-column label="图片名称" align='center'>
				<template slot-scope="scope">
                      <el-input v-model="scope.row.user_name"  @input="onExchange(scope.$index)" placeholder="请输入图片名称"></el-input>
				</template>
		</el-table-column>
        <el-table-column label="图片" align='center'>
			    <template slot-scope="scope">
					<img style="width:50px;" v-if='scope.row.response.data.path' :src="imgUrl+scope.row.response.data.path" alt="">
                        <p v-else>暂无</p>
				</template>
		</el-table-column> 
        <el-table-column label="操作" align='center'>
				<template slot-scope="scope">
                      <el-button class='butclass' type="text" @click="handledel(scope.$index)">删除</el-button>
                </template>
         </el-table-column>
         <template slot="empty">
				<img class="emptyshare" src="@/assets/cdyImg/message/blankDrawing.png" alt="">
				<p class="textshare">没有找到相关信息~</p>
		</template>
</el-table>
 <div class="pageshare">
		<el-pagination @current-change="handleCurrentChange" :current-page="page" :page-size="limit"
			 layout="total, prev, pager, next, jumper" :total="total">
		 </el-pagination>
 </div>

multiple 是多选
uploadList是当页数据,filelist全部数据

下边是逻辑代码

 handleCurrentChange(val) {
                this.page = val;
                this.pageList();
 },
 pageList(){
      this.uploadList = this.filelist.filter(
          (item, index) =>
                  index < this.page * this.limit &&
                  index >= this.limit * (this.page - 1)
         );
          this.total=this.filelist.length
 },
 handledel(index){
         this.filelist.splice((this.page-1)*this.limit+index.$index,1)
         this.pageList()
  },
 handleAvatarSuccess(res,file,filelist){
          //filelist是文件上传成功后的所有信息 this.total=filelist.length this.filelist=filelist this.uploadList=filelist this.filelist.forEach(val => { let name='' name=val.name.split('.')[0] val.user_name= JSON.parse(JSON.stringify(name)) }); this.pageList() this.loading=false; }, onExchange(index){ let moment = this.uploadList[index]; // 此处的tableData为自己的table表格绑定的data数组 this.$set(this.uploadList, index, moment); }

  以上,就是图片批量上传,并可以编辑图片名称的全部了,如有更好的方法,欢迎指教

  • 9
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值