<el-upload class="upload-demo" :data="otherinfor" :action="action" :headers="headers"
:on-preview="handlePreview" :on-remove="handleRemove" multiple :on-success="Success"
:file-list="fileList">
<el-button size="small" type="primary">点击上传</el-button>
</el-upload>
data() {
return {
headers: {},//请求头token信息
fileList: [],
//上传文件参数
otherinfor: { bizType: "新增违法测绘", bizUuid: "", folderUuid: "" },
//文件地址
action: process.env.VUE_APP_BASE_API + "/common/commonfile/uploadFile",
}
},
mounted(){//生命周期配置请求头,getToken方法是获取token,自己写
this.headers["Authorization"] = "Bearer " + getToken();
},
methods:{
//选中文件时预览
handlePreview(file) {
let url = process.env.VUE_APP_BASE_API + "/appendix" + file.url;
window.open(url);
},
// 移除文件
handleRemove(file, fileList) {
for (let i = 0; i < this.fileList.length; i++) {
if (file.name == this.fileList[i].name) {
this.fileList.splice(i, 1);
break;
}
}
},
//上传成功
Success(file, fileList) {
let obj = new Object();
obj.name = fileList.name;
obj.url = fileList.response.data.fileEntityList[0].relativePath;
this.fileList.push(obj);
},
}