实现效果描述:将列表中每一行的两张图片保存到一个对象中,再将所有对象保存到数组中,点击提交时一起提交。
实现方法:
一,元素中
action="/" :http-request="(file)=>{return imggreySuccess(file ,scope.row)}"
这两句很重要,将上传的文件和列表的这一行的数据通过函数传过去,可以在函数中接收到数据,file就是上传的图片的数据文件
<el-table
:data="getGiftListTableData"
border
style="width: 100%">
<el-table-column
prop="giftName"
label="礼物名称"
width="180">
</el-table-column>
<!-- prop="imggrey" -->
<el-table-column
label="礼物灰图"
width="180">
<template slot-scope="scope">
<el-upload file-list='imggrey' action="/" :http-request="(file)=>{return imggreySuccess(file ,scope.row)}" list-type="picture">
<el-button size="small" type="primary">点击选择图片</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
</el-upload>
</template>
</el-table-column>
<el-table-column
prop="imgColor"
label="礼物彩图">
<el-upload file-list='imggrey' action="/" :http-request="(file)=>{return imgColorSuccess(file ,scope.row)}" list-type="picture">
<el-button size="small" type="primary">点击选择图片</el-button>
<div slot="tip" class="el-upload__tip">只能上传jpg/png文件</div>
</el-upload>
</el-table-column>
</el-table>
二,在js里面添加函数接收上传的数据。
imggreySuccess(file, row) {
console.log(file);
console.log(row);
},