情景:上传视频的同时需要传递一些其它参数 与表单一起
<el-form-item label&#61;"上传视频" prop&#61;"video"><el-uploadaction&#61;"https://jsonplaceholder.typicode.com/posts/":http-request&#61;"getFile":limit&#61;"1":on-exceed&#61;"handleExceed":on-remove&#61;"handleRemove"ref&#61;"uploaddemo"><el-button size&#61;"small" type&#61;"primary">上传</el-button></el-upload></el-form-item><span><el-buttonsize&#61;"small"type&#61;"success"class&#61;"confirmUpload"&#64;click&#61;"upload">确认上传</el-button><el-button size&#61;"small" &#64;click&#61;"handleCloseDialog">取消上传</el-button></span>
data ( ) {return {file: {} }
}
getFile(item) {this.file &#61; item.file;console.log(this.file);},handleExceed(files) {this.$message.warning(&#96;当前限制选择 1 个文件&#xff0c;已选择 ${files.length} 个文件&#96;);},handleRemove(files, file) {this.$refs.uploaddemo.clearFiles();this.file &#61; {}},upload() {let fd &#61; new FormData();fd.append("video", this.file); fd.append("cameraId", this.formModel.fields.cameraId);fd.append("userId", this.formModel.fields.userId);fd.append("sortId", this.formModel.fields.sortId);let valid &#61; this.validateForm();if (valid && JSON.stringify(this.file) !&#61;&#61; "{}") {console.log(this.file);addMaterial(fd).then((res) &#61;> {console.log(res);if (res.data.code &#61;&#61; 200) {this.$message({message: res.data.message,type: "success",});this.handleGetList();this.formModel.opened &#61; false;} else {this.$message({message: res.data.message,type: "warning",});}});} else {this.$message({message: "请选择一个视频",type: "warning",});}},