<el-upload
class="upload"
accept=".txt"
ref="upload"
list-type="text"
:limit="1"
:action="uploadUrl"
:on-remove="handleRemove"
:file-list="fileList"
:on-change="changFile"
:auto-upload="false"
>
请选择文件
data{
return {
fileList: [],
}
}
computed: {
uploadUrl() {
return ‘后端的URL’
},
},
methids:{
submitData() {
const { functionTypeValue, subscriptionStatusValue, userIdStr, fileList } = this;
const formData = new FormData();
if (!fileList.length && !userIdStr) {
this.$message.error('User IDs or file,You have to choose one!');
return;
}
if (!functionTypeValue) {
this.$message.error('Function Type have to choose one!');
return;
}
if (!subscriptionStatusValue) {
this.$message.error('Subscription Type,You have to choose one!');
return;
}
let file = userIdStr ? userIdStr : fileList[0].raw;
formData.append('userIdFile', file); // file类型的文件
formData.append('userIdStr', 字段2);
formData.append('functionId', 字段3);
formData.append('validityPeriod', 字段4);
// 调接口
const { code } = grantTrailPermission(formData);
}
changFile(file, fileList) {
this.fileList = fileList;
},
handleRemove(file, fileList) {
this.fileList = fileList;
}
}