当前位置: 首页 > 知识库问答 >
问题:

javascript - 怎么在点击上传文件的时候,将上传的文件,存到对应的对象中,并刷新视图?

通俊发
2023-08-29

image.png
视图部分

<el-table :data="fileListData" border>                    <el-table-column align="center" width="50px">                      <template slot-scope="scope">                        <span v-if="scope.row.required" class="required_text"                          >*</span                        >                      </template>                    </el-table-column>                    <el-table-column                      type="index"                      label="序号"                      align="center"                      width="80"                    ></el-table-column>                    <el-table-column                      label="文件"                      prop="fileName"                      align="center"                      width="300px"                    ></el-table-column>                    <el-table-column label="附件" align="center">                      <template slot-scope="scope">                        <div v-if="scope.row.fileAnnex != ''">                          <a href="scope.row.fileAnnex"                            >{{scope.row.fileAnnexName}}</a                          >                          <el-button                            type="text"                            size="small"                            icon="el-icon-view"                            >预览</el-button                          >                          <el-button                            type="text"                            size="small"                            icon="el-icon-delete"                            >删除</el-button                          >                        </div>                        <div v-else>--</div>                      </template>                    </el-table-column>                    <el-table-column label="操作" align="center" width="120">                      <template slot-scope="scope">                        <el-upload                          class="awards_upload"                          :action="ms.base+'/ms/file/upload.do'"                          :on-remove="filePathHandleRemove"                          :limit="1"                          :data="{uploadPath:'/people/user','isRename':true,'appId':true}"                          :on-success="filePathBasicPicSuccess(scope.row.fileId)"                          :on-exceed="filePathHandleExceed"                          :on-progress="filePathHandleProgress"                          accept=".pdf"                          show-file-list="false"                          :file-list="scope.row.fileAnnex"                        >                          <el-button size="small" type="primary"                            >点击上传</el-button                          >                        </el-upload>                      </template>                    </el-table-column>                  </el-table>

js部分

fileListData: [        {          fileId: "fileName1",          fileName: "项目基本情况表(盖章后扫描为pdf版)",          fileAnnex: "",          fileAnnexName: "",          required: true,        },        {          fileId: "fileName2",          fileName: "项目简介",          fileAnnex: "",          fileAnnexName: "",          required: true,        },]
    //上传超过限制    filePathHandleExceed(files, fileList) {      this.$notify({        title: "当前最多上传1份文件",        type: "warning",      });    },    //filePath文件上传完成回调    filePathBasicPicSuccess(response, file, fileList) {      if (response.result) {        // this.filePath = response.data;        // console.log(file);        // this.ruleForm.filePath = [];        // this.ruleForm.filePath.push({        //   name: file.name,        //   url: file.url,        //   path: response.data,        //   uid: file.uid,        // });        // this.isShow = true;        console.log(this.filePath, this.ruleForm.filePath);      } else {        this.$notify({          title: response.msg,          type: "warning",        });      }    },    // 删除方法    filePathHandleRemove(file, files) {      var index = -1;      index = this.ruleForm.filePath.findIndex(function (text) {        return text == file;      });      if (index != -1) {        this.ruleForm.filePath.splice(index, 1);      }      this.isShow = false;    },    filePathHandleProgress(event, file, fileList) {      console.log(event, file, fileList);    },

共有2个答案

倪阳飇
2023-08-29

第一种:点击上传的button上添加方法,把scope.row存下来

handleUpload(row){     this.tableItem=row},

上传成功后

this.tableItem.filePath=response.datathis.$set(this.tableData,this.tableData.findIndex(item=>item.fileId===this.tableItem.fileId),this.tableItem)

第二种方法

on-success="(res,file)=>{handleAvatarSuccess(scope.row,res,file)}
百里京
2023-08-29

方法1:

<el-table    ref="table"    :data="tableData"    :key="itemKey"></el-table>// 在tableData更新的地方,顺便随机设置下key,页面就会刷新了this.itemKey = Math.random()

方法2:
用更新后的数据,覆盖之前的数据

 类似资料:
  • type String - file。 filePath String - 要上传的文件的路径。 offset Integer - 默认为0。 length Integer - 从 offset读取的字节数。默认为`0'。 modifyTime Double - 秒级的最后修改时间

  • type String - fileSystem. filsSystemURL String - 进行读取上传数据的文件系统URL。 offset Integer - 默认为0。 length Integer - 从 offset读取的字节数。默认为`0'。 modificationTime Double - 秒级的最后修改时间

  • 上传文件的功能是后端来做 点击浏览按钮能弹出选择的文件夹 点击上传的按钮需要调接口完成上传功能 下面是定义的接口和后端postman截图 只要传一个path就可以了,请问应该在Upload方法里面怎么调用接口把需要上传的文件传给后端呢

  • getFileStream光将文件转换为字符串就需要特别长的时间,再到切片,而且上传上去的文件比原来大了,再下载下来也不对

  • 问题 上传文件,并将其保存到预先设定的某个目录下。 方法 import web urls = ('/upload', 'Upload') class Upload: def GET(self): web.header("Content-Type","text/html; charset=utf-8") return """<html><head></he

  • 问题内容: 我正在尝试使用Struts 2文件上传,但是在我看来,它不起作用。下面是我的代码。 : : 我也在尝试设置struts2.multipart.saveDir属性,如您在上面看到的,但是当我阅读服务器日志时,我看到了这一行 而且文件对象为null,因为没有文件…在控制台上打印出来。我无法弄清楚这里出了什么问题。 编辑: : 问题答案: 除了更改(实际上是不必要和危险的)之外,您还没有遵循