網(wǎng)站首頁 編程語言 正文
方式一:選擇后自動(dòng)上傳
使用 http-request
覆蓋默認(rèn)的上傳行為,可以自定義上傳的實(shí)現(xiàn)
利用 before-upload
上傳文件之前的鉤子,參數(shù)為上傳的文件,若返回 false
或者返回 Promise
且被 reject
,則停止上傳
template 部分
<el-upload
class="pad"
ref="upload"
action="action"
:http-request="uploadBpmn"
:before-upload="beforeUpload">
<el-button size="medium" type="primary" class="el-icon-upload"> 部署流程定義</el-button>
</el-upload>
js 部分
beforeUpload (file) { // 上傳文件之前鉤子
const type = file.name.split('.')[1]
if (type !== 'bpmn') {
this.$message({ type: 'error', message: '只支持bpmn文件格式!' })
return false
}
},
uploadBpmn (param) { // 部署流程定義(點(diǎn)擊按鈕,上傳bpmn文件,上傳成功后部署,然后重新加載列表)
const formData = new FormData()
formData.append('processDefinition', param.file) // 傳入bpmn文件
this.$API({
name: 'deploy',
data: formData,
headers: {'Content-Type': 'multipart/form-data'}
}).then(res => {
if (res.data.code == 0) {
this.$message({ type: 'success', message: res.data.msg })
} else {
this.$message({ type: 'error', message: res.data.msg })
}
}).catch(error => {
this.$message({ type: 'error', message: error })
}).finally(() => {
this.getList()
})
},
如果不想上傳成功后顯示上傳文件列表,可以隱藏掉文件列表
可以在組件中設(shè)置 :show-file-list="false"
或者
::v-deep .el-upload-list {
display: none !important;
}
方式二:選擇后手動(dòng)上傳
<template>
<div class="app-upload">
<div class="upload-title">上傳文件</div>
<el-upload
class="upload-demo"
ref="uploadBox"
drag
action="action"
:before-upload="beforeUpload"
:http-request="upload"
:auto-upload="false"
multiple>
<i class="el-icon-upload"></i>
<div class="el-upload__text">將文件拖到此處,或<em>點(diǎn)擊上傳</em></div>
</el-upload>
<div class="upload-btn">
<el-button type="primary" @click="sure" :loading="loading">確 定</el-button>
</div>
</div>
</template>
<script>
const formData = new FormData()
export default {
data () {
return {
loading: false
}
},
methods: {
beforeUpload (file) { // 上傳文件之前鉤子
formData.append('files', file)
},
upload () {
this.loading = true
this.$API({
name: 'UploadResource',
data: formData,
params: {
path: this.$route.query.path
},
requireAuth: true
}).then (res => {
if (res.data.code === 200) {
this.$notify.success(res.data.msg)
} else {
this.$notify.error(res.data.msg)
}
}).catch(error => {
this.$notify.error(error)
}).finally(() => {
this.loading = false
this.reset()
})
},
sure () {
this.$refs.uploadBox.submit()
},
}
}
</script>
使用el-upload上傳文件夾
只需要為 input
輸入框設(shè)置 webkitdirectory
屬性
mounted() {
if (this.$route.query.type === 'folder') {
this.$nextTick(() => {
document.querySelector('.el-upload__input').webkitdirectory = true
})
}
},
原文鏈接:https://blog.csdn.net/qq_38157825/article/details/114888876
- 上一篇:沒有了
- 下一篇:沒有了
相關(guān)推薦
- 2022-05-05 C#?模式匹配完全指南_C#教程
- 2022-09-21 python?Flask框架之HTTP請(qǐng)求詳解_python
- 2022-08-03 MongoDB數(shù)據(jù)庫條件查詢技巧總結(jié)_MongoDB
- 2022-08-28 Oracle觸發(fā)器和程序包的基本介紹_oracle
- 2022-08-19 C#對(duì)桌面應(yīng)用程序自定義鼠標(biāo)光標(biāo)_C#教程
- 2023-03-21 C++將字符串格式化的幾種方式總結(jié)_C 語言
- 2022-10-09 C#實(shí)現(xiàn)選擇排序_C#教程
- 2023-01-14 GoLang逃逸分析講解_Golang
- 欄目分類
-
- 最近更新
-
- window11 系統(tǒng)安裝 yarn
- 超詳細(xì)win安裝深度學(xué)習(xí)環(huán)境2025年最新版(
- Linux 中運(yùn)行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲(chǔ)小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎(chǔ)操作-- 運(yùn)算符,流程控制 Flo
- 1. Int 和Integer 的區(qū)別,Jav
- spring @retryable不生效的一種
- Spring Security之認(rèn)證信息的處理
- Spring Security之認(rèn)證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權(quán)
- redisson分布式鎖中waittime的設(shè)
- maven:解決release錯(cuò)誤:Artif
- restTemplate使用總結(jié)
- Spring Security之安全異常處理
- MybatisPlus優(yōu)雅實(shí)現(xiàn)加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務(wù)發(fā)現(xiàn)-Nac
- Spring Security之基于HttpR
- Redis 底層數(shù)據(jù)結(jié)構(gòu)-簡(jiǎn)單動(dòng)態(tài)字符串(SD
- arthas操作spring被代理目標(biāo)對(duì)象命令
- Spring中的單例模式應(yīng)用詳解
- 聊聊消息隊(duì)列,發(fā)送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠(yuǎn)程分支