Foreword :
Implement single file upload! This article only records how to implement the code to facilitate learning and use in later projects! !
Code implementation :
<!--********** View ********** -->
<el-upload
class="upload-demo"
:http-request="UploadFile"
:show-file-list="false"
>
<el-button type="success">上传模板</el-button>
</el-upload>
//------------ script -----------
//上传模板
async function UploadFile(file) {
if (JSON.stringify(file.file) != "{}") {
formData.append("file", file.file);
let res = await UploadFileAPI(formData);
if (res.data.message == "上传成功") {
ElMessage({
type: "success",
message: "上传成功",
});
}
}
}