1.背景
在做页面时,经常需要实现上传文件功能,该自定义功能可以实现自定义上传文件的类型。
2.实现
写一个公共组件
<template>
<el-upload :accept="uploadFiles" :before-upload="beforeUpload" :multiple="multiple" action="default">
<el-button type="text" size="small">{
{$t(`common.excel.import`)}}</el-button>
</el-upload>
</template>
<script>
import { Ajax } from "@utils";
import { AjaxServiceCommon } from '@libs/coreCommon/AjaxServiceCommon.js';
import { Message } from 'element-ui';
export default {
data() {
return {
uploadFiles: ".xls,.xlsx",
};
},
props: {
api: { type: Object, required: true },
mth: { type: String, default: "get" },
multiple: { type: Boolean, default: false },
debug: { type: Boolean, default: fa