一:html结构(change事件传参函数改变)
<a-upload name="file" :multiple="true" accept=".zip,.json" :before-upload="beforeUpload" :remove="projectHandleRemove" @change="value => handleChange(value, record)"> <div @click="storageId(record)"> <a-button :disabled="!record.value||!record.value2"> <a-icon type="upload" /> 上传动效文件 </a-button> </div> </a-upload>
二:js部分(handleChange函数接受参数改变)
// 文件上传(value则是新传递过来的参数) handleChange(data, value) { let that = this if (value.fileName) { value.fileName = ‘‘ } if (data.fileList.length > 1) { //限制只上传一个文件,再次上传时则替换(覆盖)以前的文件 data.fileList.splice(0, 1) } this.$nextTick(() => { const formData = new FormData() formData.append(‘app‘, ‘suprised-file‘) formData.append(‘file‘, data.file) const file = data.file wxUploadCos({ file, cosCode: ‘suprised-file‘, loadingTitle: ‘上传中‘, originFileObj: data.file }).then(res => { if (res.data) { that.packageUrl = res.domain + res.path const params = { ‘columnId‘: that.columnId, ‘filePath‘: that.packageUrl, ‘width‘: value.value, ‘height‘: value.value2 } postAction(that.url.uploading, params).then((res) => { that.$message.success(res.msg || ‘操作成功‘) }).catch((err) => { that.$message.warning(err.msg || ‘操作失败,请稍后再试‘) }) } else { that.$message.warning(String(res.msg) || ‘文件上传失败‘) } }).catch(() => { // that[picType + ‘List‘][0].status = ‘error‘ }) }) }