赞
踩
//在表格的某一行都有一个点击上传图片的按钮,点击按钮弹出dialog弹框,在弹框中使用upload组件上传图片 </el-table> <el-table-column label="图片" width="150px" align="center"> <template slot-scope="scope"> <el-button type="text" @click="handleClick(scope.row)">上传图片</el-button </template> </el-table-column> </el-table> <!-- 上传图片对话框 --> <el-dialog title="上传图片" :visible.sync="uploadQcVisible" @closed="closePic"> <el-upload :key="timer" :action="uploadFileUrl" list-type="picture-card" :file-list="uploadFileList" :on-remove="handleRemove" :on-success="handleSuccss" multiple > <i class="el-icon-plus" /> </el-upload> </el-dialog> //:key='timer' 定义一个timer变量 是为了重载组件使用 //点击上传,打开对话框,此时暂存row数据 handleClick(row){ //打开对话框 this.uploadQcVisible = true //定义全局变量接收row,row代表表格每一行的数据,每一行的row对象下边有一个piclist数组来存放上传的图片 this.tempObj = row //判断row.piclist是否已经传过数据 if(row.piclist.length !== 0){ this.uploadFileList = Object.assign([],row.piclist) } } // 上传成功,push到当前行的piclist数组中 handleSuccss(res, file, fileList) { this.tempObj.piclist.push({ name: file.name, url: res.data, status: file.status, uid: file.uid }) }, //关闭对话框时,重载组件,并且把uploadFileList清空,否则会有异常 closePic() { this.timer = new Date().getTime() this.uploadFileList = [] }, // 移除图片 handleRemove(file, fileList) { this.tempObj.piclist = Object.assign([], fileList) },
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。